Friday, 2 January 2015

grid traversal (smart way ;) ) with bfs

now to move in the four direction of a grid we can use
int positionsX[4]= {0,-1,0,1};
int positionsY[4]= {-1,0,1,0};

how to use it in the code part 
for(int i=0;i<4;i++){
int newx=top.first+positionsX[i],newy=top.second+positionsY[i];
}

we can also use a function 
(validPosition(newx,newy))
and put the necessary condition in it , to make sure that the newly formed position is correct

code example

(with bfs traversal in a grid)
spoj question -> BITMAP

SOLUTION LINK



No comments:

Post a Comment