Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<class VisitorClass>
- void DFSVisit(const Graph &graph, int vertex, VisitorClass visitor, std::vector<bool> *used) {
- (*used)[vertex] = true;
- visitor.OnStartVertexVisit(vertex);
- for (auto edge: graph.GetOutcomingEdgesList(vertex)) {
- if (!(*used)[edge.to]) {
- DFSVisit(graph, edge.to, visitor, used);
- }
- }
- visitor.OnEndVertexVisit(vertex);
- }
- template<class VisitorClass>
- void DFS(const Graph &graph, const std::vector<int> &vertice_order, VisitorClass visitor) {
- std::vector<bool> used(graph.GetNumberOfVertices());
- for (auto vertex: vertice_order) {
- if (!used[vertex]) {
- visitor.OnStartVertex(vertex);
- DFSVisit(graph, vertex, visitor, &used);
- }
- }
- }
- template<class VisitorClass>
- void DFS(const Graph &graph, VisitorClass visitor) {
- std::vector<int> standart_order(graph.GetNumberOfVertices());
- std::iota(standart_order.begin(), standart_order.end(), 0);
- DFS(graph, standart_order, visitor);
- }
Advertisement
Add Comment
Please, Sign In to add comment