How would you sort 5 parallel arrays in ascending order?
Printable View
How would you sort 5 parallel arrays in ascending order?
I would prefer an array of structs as it is easier to handle and reason about, plus it easily allows for the use of standard algorithms like std::sort.
If I understand what you're talking about right, you basically want to create a sixth temporary array that tracks the position of where all the original elements are. Then sort whichever array you're basing the sort off of. As you do this, keep up with the changes in the temporary array. Once you're done sorting the first, use the sixth to sort two through five.