You can do it in an understandable way, like that:
Read the two-dimensional array:
1 2 3 4 5 6
|
for(i=1; i<=n; i++)
{for(j=1; j<=m; j++)
{ cout<<"v["<<i<<"]["<<j<<"]=";
cin>>v[i][j];
}
}
|
Now, you have to place the two-dimensional array into an one-dimensional array (into a vector) like that:
1 2 3 4 5 6 7 8
|
int x=1;
for(i=1; i<=n; i++)
{ for(j=1; j<=m; j++)
{ k[x]=v[i][j];
x++;
}
}
x--;
|
Now you have the two-dimensional array into an one-dimensional one. You can now apply the bubble-sort implementation from my last post for that array (k).
Next, you have to put the sorted vector in the original array (v), like that:
1 2 3 4 5 6 7
|
x=1;
for(i=1; i<=n; i++)
{ for(j=1; j<=m; j++)
{ v[i][j]=k[x];
x++;
}
}
|
This is an unefficient way to do that because I use 6 loops just for that sorting and overall I think that will be about 8 (including the printing on the screen).
Also, you can do it using just one traverse but it's a bit complicated because you'll have about 3 for-loops in a do-while loop, and that can damage your system.