Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please help me with the following question. the two functions dfs and bfs are explained as to the context the refer to in the actual
please help me with the following question. the two functions dfs and bfs are explained as to the context the refer to in the actual question. thank you!
QUESTION:
What is not specified in the functions dfs() and bfs() is what to do when you visit each node. Modify the two functions to accept an input parameter that accepts a function with the prototype:
void visit(T node) What this function does is left up to the person using your classes. You will need to call the function at the correct point in your code.
void dfs(Graph &g, T &startNode) : Do a depth-first traversal of the graph g, starting from node startNode. You may either print the contents of each node or implement the extra credit portion of the assignment.
void bfs(Graph &g, T &startNode) : Do breath-first traversal of the graph g, starting from node startNode. You may either print the contents of each node or implement the extra credit portion of the assignment
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