0

given a 2D array for eg.

int  arr[2][5] = { {5 , 3 , 4 , 1 , 2},{7 , 4 , 0 , 8 , 2}};

now I am sorting first row in ascending order and correspondingly 2nd row elements are also shifted. altered 2D array

int arr[2][5] = { {1 , 2 , 3 , 4 , 5},{8 , 2 , 4 , 0 , 7}};

I am using heapsort algo for acheiving this but i have to write whole code everytime. I want to know some way to acheive this using c++ standard functions. plzz someone help me out on this :)

1 Answers1

0

With the current algorithms you'd need to "zip" the two ranges into a common view of elements from both ranges ordered according to the key of the first range. Creating a corresponding random access iterator is mostly straight forward except for the somewhat unfortunate constraint that operator*() is supposed to yield a reference to the respective elements.

I think Boost has a zip-range providing the corresponding functionality.

Dietmar Kühl
  • 150,225
  • 13
  • 225
  • 380