Using your code just use std::sort on each row of the multidimensional array. ie.
#include <iostream>
using namespace std;
int main(){
int a[2][3];
a[0][0]=1;
a[0][1]=7;
a[0][2]=3;
a[1][0]=6;
a[1][1]=2;
a[1][2]=5;
for(int i = 0; i < 2; i++) {
sort(a[i],a[i]+3);
}
for(int row = 0; row < 2; row++) {
for(int col = 0; col < 2; col++) {
cout << a[row][col] << " ";
}
}
return 0;
}
I initiated every element of your multidimensional array a, since your declared a to be size 6 (2 rows, 3 columns). This would output 1 3 7 2 5 6, because it sorts the rows from least to greatest. If you wanted to sort the multidimensional array so that the output would read 1 2 3 5 6 7 then you would need to do something like this:
#include <iostream>
using namespace std;
int main(){
int a[2][3];
int b[6];
int count = 0;
a[0][0]=1;
a[0][1]=7;
a[0][2]=3;
a[1][0]=6;
a[1][1]=2;
a[1][2]=5;
for(int row = 0; row < 2; row++) {
for(int col = 0; col < 3; col++) {
b[count] = a[row][col];
count++;
}
}
sort(b, b+6);
count = 0;
for(int row = 0; row < 2; row++) {
for(int col = 0; col < 3; col++) {
a[row][col] = b[count];
count++;
}
}
for(int row = 0; row < 2; row++) {
for(int col = 0; col < 3; col++) {
cout << a[row][col] << " ";
}
}
return 0;
}
This second example is probably the worst possible way to go about sorting a multidimensional array though. Let me know if you find an error in my code, I was unable to test, or need additional help.