Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a program ( in main.cpp ) that: Prompts the user for a filename containing node data. Outputs the nodes of a graph in a
Write a program in main.cpp that:
Prompts the user for a filename containing node data.
Outputs the nodes of a graph in a depth first traversal.
infoNote: Files ChExData.txt and ChExData.txt contain node data that you may test your program with.
Here is my code:
main.cpp
#include
#include
#include
#include
using namespace std;
void depthFirstTraversalconst vector& graph, int start
vector visitedgraphsize false;
stack s;
spushstart;
while sempty
int node stop;
spop;
if visitednode
cout node ;
visitednode true;
for int neighbor : graphnode
if visitedneighbor
spushneighbor;
int main
string filename;
cout "Enter filename containing node data: ;
cin filename;
ifstream inputFilefilename;
if inputFile
cerr "Error opening file." endl;
return ;
int numNodes;
inputFile numNodes;
vector graphnumNodes;
for int i ; i numNodes; i
int node;
inputFile node;
while node
graphipushbacknode;
inputFile node;
inputFile.close;
cout "Depth First Traversal:" endl;
for int i ; i numNodes; i
cout "Starting from node i : ;
depthFirstTraversalgraph i;
cout endl;
return ;
the code is working yet the parameter that is being asked is not being approved, please help.
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