YOU CAN JUST WRITE THE SECOND FUNCTION(3.2dfs) IMPORTANT: C++ question. thx 3.1
ID: 3699528 • Letter: Y
Question
YOU CAN JUST WRITE THE SECOND FUNCTION(3.2dfs)
IMPORTANT: C++ question.
thx
3.1 BFS. Write a method that prints the vertices in a graph visited in a breadth-first search (BFS) and the verntex with the maximum number of adjacent nodes. void Graph::findNodewithMaximumAdjacent (string); The function should print the BFS sequence and the node that has the maximum number of adjacent nodes. The argument of the function is the starting point of BF Example. For the following graph, 10 25 35 40 The expected output by calling findNodewithMaximumAdjacent ("10") should be 10 25 35 40 25 The first line prints out the BFS traversal sequence, while the second line prints out the node(s) that has maximum number of adjacent nodes. When multiple nodes have same number of maximum number of adjacent nodes, print out all nodes Hint. Use BFS algorithm to traverse the graph, while keep track of number of adjacent nodes for each node.Explanation / Answer
/*If you have any query do comment in the comment section else like the solution*/
void Graph::DFSpathUtil(string src,string dest, bool visited[])
{
visited[src] = true;
cout <<src;
if(src==dest)
return;
else
cout<<" --> ";
list<int>::iterator it;
for (it=adj[src].begin();it!=adj[src].end();it++)
if (!visited[*it])
DFSUtil(*it,dest, visited);
}
void Graph::DFSpath(string src,string dest)
{
bool *visited = new bool[V];
for (int i = 0; i < V; i++)
visited[i] = false;
DFSUtil(src,dest,visited);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.