0

I wanted, to do program which sorts 2D array by the first dimension so that means, that it gets sorted by the first dimension and the second dimension goes where the first has gone.

for example I want array a[4][2]=[["3", "4"], ["1", "7"], ["6", "8"], ["5", "1"]] becomes [["1", "7"] ["3", "4"] ["5", "1"] ["6", "8"]], so with the program:

int a[10][2];
    for (int i=0;i<10;i++){
        a[i][0]=10-i;
        a[i][1]=i;
    }
    sort(a[0],a[10]);
    for(int i=0;i<10;i++)
        cout<<a[i][0]<<" "<<a[i][1]<<" ";
    }

I want cout "1 9 2 8 3 7 4 6 5 5 6 4 7 3 8 2 9 1 10 0" but cout is "0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10". How can I do it?

  • What is `a[10]`? Just use `std::vector` and `std::sort()`. – tadman Oct 29 '22 at 20:44
  • You can't use `std::sort` because array types aren't move-assignable or move-constructible. You'll have to make your own sort function. – Nelfeal Oct 29 '22 at 21:08

0 Answers0