Question: I need help implementing following functions: void Graph::printDFS(){ } void Graph::DFTraversal(vertex* v){ } void setAllVerticesUnvisited(){ } ======================================= #include #include struct vertex; /*This is the struct
I need help implementing following functions:
void Graph::printDFS(){
}
void Graph::DFTraversal(vertex* v){
}
void setAllVerticesUnvisited(){
}
=======================================
#include
struct vertex;
/*This is the struct for the adjacent vertices for each vertex in the graph. */
struct Edge { vertex *v; int distance; };
/*this is the struct for each vertex in the graph. */ struct vertex { std::string name; int district; bool visited; std::vector
class Graph { public:
/* Method Name: printDFS Purpose: Iterate through the vertices, perform DFS by calling the DFTraversal function Parameters: none */ void printDFS();
/* Method Name: setAllVerticesUnvisited Purpose: Iterate through the vertices, mark them unvisited. This function is called prior to calling DFS after BFS has been performed so that the nodes can revisited again when DFS is called. Parameters: None */ void setAllVerticesUnvisited();
private:
void DFTraversal(vertex *v);
};
===============================
void printDFS() Print the names of the cities in the order they are visited during a depth-first traversal. Hint: It can be written recursively using the DFTraversal helper function. Also, call setAllVerticesUnvisited so that none of the cities are visited before your traversal.
void setAllVerticesUnvisited() Set the visited member of each vertex to be false . This should be called right before any traversal that uses the visited member.
void DFTraversal(vertex *v) This helper function should perform a depth-first traversal of the graph, starting from v, and print out each node as it is visited.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
