4fd800b3a8 2011-02-23 kinaba: // code template for BFS 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: State start = /*start*/; 4fd800b3a8 2011-02-23 kinaba: vector<State> Q( 1, start ); 4fd800b3a8 2011-02-23 kinaba: set<State> V; V.insert(start); 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: for(int step=0; !Q.empty(); ++step) 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: vector<State> Qold; Qold.swap(Q); 4fd800b3a8 2011-02-23 kinaba: for(int qi=0; qi<Qold.size(); ++qi) 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: State& cur = Qold[qi]; 4fd800b3a8 2011-02-23 kinaba: if( /*isGoal(cur)*/ ) 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: 4fd800b3a8 2011-02-23 kinaba: foreach(next) 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: if( !V.count(next) ) 4fd800b3a8 2011-02-23 kinaba: { 4fd800b3a8 2011-02-23 kinaba: V.insert(next); 4fd800b3a8 2011-02-23 kinaba: Q.push_back(next); 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: } 4fd800b3a8 2011-02-23 kinaba: }