How do you sort matrices in C++?
How can I sort a matrix, stored as an array of integers, by row? For example, given the matrix: 3 1 2 1 6 4 2 4 7 I'd like to sort it by the correct order of the first row, keeping all the columns in their current status and turning it into: 1 2 3 6 4 1 4 7 2 I've tried several times by using the command sort, including the library algorithm, typing: sort(&A[0][0], &A[0][2]); //A is my matrix but it just order each each line, without then moving the elements underneath the first line consequently. I'm new to C++ and I don't know much about it, I've also tried by writing a different version of InsertionSort to achieve this specifical result, and it works but changes some numbers in some way that I can't understand. Is there a simple way to achieve this result with basic commands? Or, is there anything I may be doing in the wrong way?