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