ACM模板
C++queue的应用
struct note{
int x;
int step;
int y;
};
void BFS(note front_head)
{
queue<note>Q;
Q.push(front_head);
note next_queue;
note now_head;
while(!Q.empty())
{
now_head = Q.front();
Q.pop();
for(i = 0; i < 8; i ++)
{
next_queue.x = now_head.x + NEXT[i][0];
next_queue.y = now_head.y + NEXT[i][1];
if(next_queue.x < 0||next_queue.y <0||next_queue.x > 7||next_queue.y > 7)
continue;
if(book[next_queue.x ][next_queue.y ]!= 1)
{
book[next_queue.x ][next_queue.y ] = 1;
next_queue.step = now_queue.step+1;
Q.push(next_queue);
if(next_queue.x == end_i&&next_queue.y == end_j)
{
step = next_queue.step;
return;
}
}
}
}
return;
}