samedi 21 mai 2022

Sorting an array whose elements are attached to another array [duplicate]

I have an array (say) arr1 = [9,4,2,5] and another array arr2 = [1,6,3,7]

I want to sort arr2 and I also want to change swap elements of arr1 as per arr2.

so think of it as the elements of at same index of both arrays are attached. like 9 of arr1 and 1 of arr2 are attached. similarly, the other elements are.

so if arr2 is sorted which is [1,3,6,7] I want arr1 to have elements in this order [9,2,4,5]

Is there a way to do that directly in c++ using stl?

Aucun commentaire:

Enregistrer un commentaire