#include <stdio.h>
#define MAX 10
void selectionSort(int data[MAX])
{
int lowestIndex = 0;
int lastPointer = 0;
int selectorPointer = 0;
while (lastPointer < (MAX - 1))
{
if (lastPointer == selectorPointer || data[lowestIndex] > data[selectorPointer])
{
lowestIndex = selectorPointer;
}
if (selectorPointer == (MAX - 1))
{
int temporary = data[lastPointer];
data[lastPointer] = data[lowestIndex];
data[lowestIndex] = temporary;
lastPointer++;
selectorPointer = lastPointer;
}
else
{
selectorPointer++;
}
}
}
void main()
{
int data[] = {3, 10, 4, 6, 8, 9, 7, 2, 1, 5};
printf("Before: ");
for (int i = 0; i < MAX; i++)
{
printf("%d ", data[i]);
}
selectionSort(data);
printf("\nAfter: ");
for (int i = 0; i < MAX; i++)
{
printf("%d ", data[i]);
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: