How can I sort three arrays by sorting an only a single array?
int arr[]={20,10,5,22};
int arr2[]={120,344,43,122};
int arr3[]={2234,12,23,3434};
what I want is to sort the first array arr and the remaining arrays must be sorted according to the index of the first array.
output:
5 10 20 22
as in above arr
before sorting index of 5 was 3 now it is 0. similarly index of 43 and 12 should be changed to 0
expected arrays after sorting would be would be
5 10 20 22
43 344 120 122
23 12 2234 3424
what I want as we swap element in bubble sort or any other swap we change to index of element by swapping. i want similar to other two arrays.
swap(arr[0],arr[2])
swap(arr1[0],arr1[2])
swap(arr2[0],arr2[2])
This is possible if I implement custom sorting but want something that will reduce code.