Originally posted by Unregistered
I've sorted them using string compare but that is sorting by string while I'm wanting a sort by integer. Can you elaborate on your response. Thanks
I think he means something like this:
Code:
struct blah {
int number;
string stuff;
}
sorting algorithm(blah a[])
{
for(int i = 0 ; i < range-1; i++) {
....
....
....
//assuming a[i+1].number < a[i].number
tempstring = a[i+1].stuff;
tempnumber = a[i+1].number;
a[i+1].stuff = a[i].stuff;
a[i+1].number = a[i].number;
a[i].stuff = tempstring;
a[i].number = tempnumber;
}
}
You can use various sorting algorithms for that but essentially the idea is the same. You can however create two seperate arrays but, again it would be done the same way. Using a struct or even a class just simplifies everything. You shouldn't be able to make it a 2 dimensional array since 1 side is an integer and the other side is a string.