Answer the question
In order to leave comments, you need to log in
How to "pull" the elements of the second array while sorting the first one in c++?
How to sort the first array, pull the elements of the second one using the stl c++ sorting functions?
Example:
5 11 27 14 8 19 11
8 10 12 20 3 17 7
----------------------
5 8 11 11 14 19 27
8 3 10 7 20 17 12
Answer the question
In order to leave comments, you need to log in
2 options:
1) make a new array with pair, write elements from two arrays there, sort.
2) create a new array, fill it with numbers from 0 to n-1. Pass your sorting function to sort, which compares not the passed numbers a and b, but the elements of the first array by these indices (array1[a] and array1[b]). Then use the resulting set of indices to display the second array (if you sorted the indices array, then output array2[indices[i]], for i from 0 to n-1).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question