void DFSImplementation (const IGraph& graph, Visitor& visitor, std::vector<bool>& visited, int vertex_start) { std::stack <int> vertices_stack; vertices_stack.push(vertex_start); while (!vertices_stack.empty()) { int current_vertex = vertices_stack.top(); if (!visited[current_vertex]) { visited[current_vertex] = true; visitor.StartProcessingVertex(current_vertex); std::vector<int> current_vertex_incidences = graph.GetIncidenceList(current_vertex); for (int i = 0; i < current_vertex_incidences.size(); ++i) { int next_incident_vertex = current_vertex_incidences[i]; visitor.ProcessingEdge(current_vertex, next_incident_vertex); if (!visited[next_incident_vertex]) vertices_stack.push(next_incident_vertex); } } else { visitor.LeaveVertex(current_vertex); vertices_stack.pop(); } } } if (!visited[vertex]) DFSImplementation(graph, visitor, visited, vertex);
inline void TestIGraphGetIncidenceList(const IGraph& graph, const std::vector<Edge> &list_of_edges, int vertex) { std::unordered_set<int> right_insidence_vertices_set; std::vector<int> incidence_list = graph.GetIncidenceList(vertex); std::unordered_set<int> incidence_vertices_set(incidence_list.begin(), incidence_list.end()); for (int edge_index = 0; edge_index < list_of_edges.size(); ++edge_index) { if (list_of_edges[edge_index].begin_ == vertex) { right_insidence_vertices_set.insert(list_of_edges[edge_index].end_); } } if (incidence_vertices_set != right_insidence_vertices_set) { throw std::logic_error("IGraph::GetIncidenceList : FAIL"); } }