#include<iostream>;
using namespace std;
int queuex[];
int queuey[];
int visit[][];
int dx[]={-1,0,0,1};
int dy[]={0,1,-1,0};
int rear;
int BFS(int startx, int starty)
{
int front = rear = 0;
queuex[rear]=startx;
queuey[rear]=starty;
rear++;
visit[startx][starty]=1;
while(front !=rear)
{
int x = queuex[front];
int y = queuey[front];
front++;
for(int move = 0; move <4; move++)
{
int xNext = x + dx[move];
int yNext = y + dy[move];
if(visit[xNext][yNext]==0)
{
queuex[rear]=xNext;
queuey[rear]=yNext;
rear++;
visit[xNext][yNext] = 1;
}
}
}
return -1;
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.