我想排序2維array.the原始數組2維數組是排序在C
5 0 3
4 1 2
3 1 1
4 2 2
3 3 1
當排序,應該是這樣
3 1 1
3 3 1
4 2 2
4 1 2
5 0 3
這裏是我的代碼用於嘗試實現Bubble Sort,我表示行數。
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;
}
}
}
它仍然沒有排序,任何幫助將不勝感激。
你的支架樣式是好奇。 – moonwave99
爲什麼'4 2 2'出現在'4 1 2'之前? – pmg
好的提示是你不要在循環之外使用變量'x'。 – Hogan