keeping relation while sorting arrays

Hi,
I have a array of 2 d of name ( grrr caracters)
and a array of distance ( int )related to the name.
ex
Atown 20
Btown 34
... ..
so i know that array_number[0] is 20 is related to well array_name[0][0] ..[0][4]
line 0

but now i need to sort ( selection) by recursion the array of numbers.Is there a way possible
to keep the relation.

Unfortunately, I am to low level to use string, vector,pointer.

thx after 4 days any fresh ideas will be appreciated.
I'm not entirely sure what you're asking, but if you want to enforce a relation between two elements of different arrays, it's usually a good idea to turn it around and make it an array of relations of two elements.

Now:
array_num[i] (int) <-> array_name[i] (char*)
If you swap two array_num's, the relation is lost/corrupted.

Instead, make a struct with an int and char* member:
1
2
3
4
struct someName {
    int num;
    char* name;
}

Then, make an array of someName structs. The relation now becomes:
someNameArray[i].num <-> someNameArray[i].count
If you swap two elements of the array, the relation is still correct, because you're swapping pairs of {num, name}.

Topic archived. No new replies allowed.