BFS代码框架

来自B站浙师大视频,点击地址

struct node{
      state;
      int step;
}now,next;
int bfs(){
       queueq;
        now.state=init_state;
        now.step=0;
        q.push(now);
        visit[init_state]=true;
        while(!q.empty()){
                now=q.front();
                q.pop();
                for(....){
                      next.state=change(now.state);
                      next.step=now.step+1;
                      if(next.state==goal_state)
                                      return next.state;
                       if(visit[next.step]=true]) continue;
                       visit[next.state]=true;
                       q.push(next);
                    }
              }
  }

你可能感兴趣的:(BFS代码框架)