
Untitled
By: a guest on
May 5th, 2012 | syntax:
None | size: 0.62 KB | hits: 12 | expires: Never
Visiting all locations in a multidimensional array directly adjacent to some location?
XXX
XOX
XXX
for (int i = x - 1; i <= x + 1; i++) {
for (int j = y - 1; j <= y + 1; j++) {
/* Skip the point itself! */
if (i == x && j == y) continue;
/* Process the location here */
}
}
for (int i = x - 1; i <= x + 1; i++) {
for (int j = y - 1; j <= y + 1; j++) {
if ((i == x) == (j == y)) continue;
/* Process the location here */
}
}
array[i-1][j-1];
array[i-1][j];
array[i-1][j+1];
array[i][j-1];
array[i][j+1];
array[i+1][j-1];
array[i+1][j];
array[i+1][j+1];