say i have a two dimensional array a[512][512]. There is one more 2D array b[512][512]. The algorithm is like this depending on value of a[i][j] i have compare b[j][k] with two of its neighbour. This is a part of that algorithm if(a[j][k]==0) { if(b[j][k]>=b[j][k+1] && b[j][k]>=b[j][k-1]) some code here } the problem is when k=0 b[j][k-1] will be b[j][0-1]=b[j][-1]. To handle ...