Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago