I ve got a 2-D array that looks as such

23 hey

34 are

29 how

38 you

26 there

How would I sort the first column of integers while also bringing over the strings so that I get

23 hey

26 there

29 how

34 are

28 you

Thanks

Printable View

- 04-02-2002UnregisteredSort 2-d arrays
I ve got a 2-D array that looks as such

23 hey

34 are

29 how

38 you

26 there

How would I sort the first column of integers while also bringing over the strings so that I get

23 hey

26 there

29 how

34 are

28 you

Thanks - 04-02-2002SilentStrike
It looks like a 1D array to me. Perhaps you mean a parrallel array?

Sort the array of integers. Everytime you copy something from n to m, copy the corresponding parrallel array index from n to m.

Better yet, use a struct with an int and a string, and just sort based on the integer part. - 04-02-2002Unregistered
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

- 04-03-2002prophetQuote:

*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**

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;

}

}