Question
DFS Traversal Help void Graph::printDFS() { } void Graph::DFTraversal(vertex* v) { } Given: #ifndef GRAPH_HPP #define GRAPH_HPP #include #include struct vertex; struct Edge { vertex
DFS Traversal Help void Graph::printDFS() { } void Graph::DFTraversal(vertex* v) { }
Given:
#ifndef GRAPH_HPP #define GRAPH_HPP
#include
struct vertex;
struct Edge { vertex *v; int distance; };
struct vertex { std::string name; int district; bool visited; std::vector
class Graph { public: Graph();
~Graph();
void addEdge(std::string v1, std::string v2, int distance);
void addVertex(std::string name);
void displayEdges();
void assignDistricts();
void printDFS();
void setAllVerticesUnvisited();
private: std::vector
vertex *findVertex(std::string name);
void BFTraversalLabel(std::string startingCity, int distID);
void DFTraversal(vertex *v);
};
#endif
What I have so far:
void Graph::printDFS() { for(int i = 0; i < vertices.size(); i++) { cout << vertices[i].name; for(int j = 0; j < vertices[i].Edges.size(); j++) { if (j != vertices[i].Edges.size()-1); else cout << endl; } } }
void Graph::DFTraversal(vertex* v) { if (!v) return;
cout << v; // visit node DFTraversal(v -> left); DFTraversal(v -> right); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started