4 #include "../containers/graph.h"
5 #include "../containers/vertex.h"
6 #include "../containers/edge.h"
7 #include <unordered_map>
21 template<
typename OutputIter>
27 typedef typename std::iterator_traits<OutputIter>::value_type val_type;
29 std::vector<val_type> postorder(G.no_of_vertices());
31 dfs_order(G, postorder.begin());
33 return copy(postorder.rbegin(), postorder.rend(), dest);
39 template<
typename OutputIter>
45 std::unordered_map<Vertex*, bool, UndirectedGraph::Hasher> visited;
46 std::vector<Vertex*> pvertex_list(G.no_of_vertices());
47 G.get_vertices(pvertex_list.begin());
49 for(
auto& pvertex : pvertex_list)
50 visited[pvertex] =
false;
53 std::vector<Vertex*> dfs_list(G.no_of_vertices());
55 std::vector<Vertex*>::iterator dfs_it = dfs_list.begin();
58 for(
auto& pvertex : pvertex_list) {
59 auto prev_it = dfs_it;
61 dfs(G, pvertex, visited, dfs_it);
62 for(
auto it = prev_it; it != dfs_it; it++) {
OutputIter connected_components(UndirectedGraph &G, OutputIter dest)
Definition: graph_algo.h:40
OutputIter topological_sort(UndirectedGraph &G, OutputIter dest)
Definition: graph_algo.h:22