// // Created by rafalbyczek on 13.06.16. // #ifndef ZADANIE_K_BFS_BFS_H #define ZADANIE_K_BFS_BFS_H #include #include #include using namespace std; template void bfs(T begin, T end, S comp, U sasiad, V akcja) { auto a = *begin; queue Q; set A(comp); typename set::iterator f; for (auto it = begin; it != end; it++) { Q.push(*it); } while(!Q.empty()) { auto x = Q.front(); Q.pop(); for(auto it = sasiad(x).first; it != sasiad(x).second; it++) { auto a = *it; f = A.find(a); if(f == A.end()) { A.insert(a); akcja(a); Q.push(a); } } } } #endif //ZADANIE_K_BFS_BFS_H