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 #include

struct vertex;

struct Edge { vertex *v; int distance; };

struct vertex { std::string name; int district; bool visited; std::vector Edges; //stores edges to adjacent vertices };

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 vertices;

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!