I am trying to sort a 2 dimensional array.the original array is
5 0 3
4 1 2
3 1 1
4 2 2
3 3 1
When sorted, it should be like
3 1 1
3 3 1
4 2 2
4 1 2
5 0 3
Here is the code i used trying to implement Bubble Sort,i represents the number of rows.
int x,y,z,j,temp1,temp2,temp3;
for(x=0;x<i;x++)
{
for (j=0;j<i-1;j++)
{
if(a[j][0]>a[j+1][0])
{
temp1=a[j][0];
temp2=a[j][1];
temp3=a[j][2];
a[j][0]=a[j+1][0];
a[j][1]=a[j+1][1];
a[j][2]=a[j+1][2];
a[j+1][0]=temp1;
a[j+1][1]=temp2;
a[j+1][2]=temp3;
}
}
}
it still does not sort, any help will be greatly appreciated.
4 2 2come before4 1 2?xoutside of its loop.