2013-10-26 33 views
0

我想在C#中手動排序一個二維數組。 我很困惑當指針位於索引0時該怎麼辦,我需要去前一行。 我的問題,當我到達索引0我不能再進一步,它是然後出界。在C中排序一個2d的整數數組#

int temp3 = 25; 
     bool swap = false; 
     bool swap2 = false; 
     long pointer = productarray[4,4]; 
     for(int i = 4; i >= 0; i--){ 

      for(int j = 4; j >= 0; j--){ 
       int temp5 = 1; 
       while(swap != true){ 

        if(temp3 != temp5){ 
         pointer = productarray[i,j]; 

          if (pointer < productarray [i, j - temp5]) { 
           long temporary = productarray [i, j]; 
           productarray [i, j] = productarray [i, j - temp5]; 
           productarray [i, j - temp5] = temporary; 
           temp5 = 1; 


          } else { 
           temp5++; 

          } 

        } 
        else{ 
         swap = true; //Current pointer is the greatest int 
         temp3--; 
        } 
       } 
       swap = false; 

      } 
     } 
+0

及其2D陣列。你的意思是指數0,0?你目前有什麼代碼? – paqogomez

+0

需要更多的信息.​​..你能提供一個例子嗎? – Mayank

+0

@paqogomez我的意思是如果我在第3行col 0,我想比較它的一個元素將如何通過前循環使用for循環。 –

回答