Insertion sort not working!

I'm trying to use insertion sort to sort a list by names and it's obviously not working. I used the same code to sort by ID numbers so I'm not sure why it's not working.

void sortByNameInsert(Students info[], int i, string key, Students key2[])
{
int j;
j = i-1;

while(info[j].name > key && j>=0)
{
info[j+1].name = info[j].name;
j--;
}

info[j+1] = key2[i];
}


void sortByName(Students info[], int count)
{
string key;
Students key2[MAXSIZE];

for(int i=1; i<count; i++)
{
cout << i << endl;
key = info[i].name;
sortByNameInsert(info, i, key, key2);
}
}
Last edited on
Topic archived. No new replies allowed.