Sorting of an 2d array using compare fun

if i giving you an array of e.g.=>
1 5
2 7
3 6
4 5
1 9

sorted array of above–>
1 5
1 9
2 6
3 5
4 5

so for this what can I do??

@ankit_verma hey, Create a temp[] array of size n^2. Starting with the first row one by one copy the elements of the given matrix into temp[]. Sort temp[]. Now one by one copy the elements of temp[] back to the given matrix.

i think this is not proper way it is not working like that i want output.

@ankit_verma how do you want your sorting ,Please elaborate your ouput.