[問題] 表示二維array的上下左右 style問題
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
GCC
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
無
問題(Question):
我有一個二維array表示一個被分割成很多格子的平面
其中有一個運算邏輯是要對其中一個格子的上下左右做一件事
不過不知道怎樣的style可以讓後面閱讀我程式碼的人比較好懂
目前是這樣的方式
//int row,col is the coordinate of target cell
for(int i=-1; i<=1; i=i+2){
for(int j=-1; j<=1; j=j+2){
if( checkBoundry (row+i, col+j) ){ // execute foo only if in the array
foo (array[row+i][col+j]); //will modify element in the 2D array
}
}
}
這邊莫名卡很久,這是我目前想到比較易懂的方式
可是感覺還是怪怪的,好像無法一眼看出這段在幹嘛
好像要跟著兩個for的iterator走過一遍才了解為什麼要這樣寫
想知道有沒有更好的寫法
謝謝~
--
人只有兩個時候才會感受到自己存在:
大幅進步時、大幅墮落時
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.112.233.230
※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1403688998.A.58D.html
→
06/25 18:31, , 1F
06/25 18:31, 1F
推
06/25 19:35, , 2F
06/25 19:35, 2F
→
06/25 19:36, , 3F
06/25 19:36, 3F
→
06/25 19:36, , 4F
06/25 19:36, 4F
→
06/25 19:37, , 5F
06/25 19:37, 5F
→
06/25 22:34, , 6F
06/25 22:34, 6F
→
06/25 22:35, , 7F
06/25 22:35, 7F