So I have my selection sort sorting a list of a student array of structs on the student ID number. The issue I am having is that it isn't sorting just the last two of each file, and I can't figure out what is wrong.
void assortList(STUDENT* list, int size)
{
int startScan;
int minIndex;
int minValue;
for(startScan = 0; startScan < (size - 1); startScan++)
{
minIndex = startScan;
minValue = list[startScan].ID;
for(int index = startScan + 1; index < size; index++)
{
if(list[index].ID < minValue)
{
minValue = list[index].ID;
minIndex = index;
}
STUDENT temp = list[minIndex];
list[minIndex] = list[startScan];
list[startScan] = temp;
}
}
for(int x = 0; x < size; x++)
{
FLUSH;
printf("%d %s\n", list[x].ID, list[x].name);
}
printf("\n");
}
Output
List 1:
1189 Shmoys, David
1234 Marley, Tom
2901 Green, Mary
2908 Vigoda, Eric
3456 Karlin, Anna
4344 Kelley, Sandra
5445 Homer, Steve
5567 Welch, Jennifer
6566 Williams, Ryan
6579 Vadhan, Salil
8372 Chen, Li
8879 Bein, Wolfgang
8999 Fenner, Mia
9002 Khuller, Samira
9123 Vianu, Victor
9865 Beame, Paul
6766 Hemaspaandra, Lane
8433 Chakrabarti, Amit
List 2
1111 Tan, Li-Yang
2000 Barenboim, Leonid
2001 Rossman, Marie
3456 Karlin, Anna
4344 Kelley, Sandra
5445 Homer, Steve
5511 Welch, Claire
6577 Green, Susan
8433 Chakrabarti, Amit
8800 Servedio, Rocco
8999 Fenner, Mia
9123 Vianu, Victor
9865 Beame, Paul
6009 Mumey, Brendan
6666 Forbes, Michael
You'll notice from the output, that it is just the last two students of each list (6766, 8433 in the first set; 6009 and 6666 in the second set) that are not being sorted.