Question
//mazegraph.cpp #include mazegraph.h #include mazegraph::mazegraph() { int vertex; cin >> size; cin >> start; cin >> exit; assert(0 vertex; while(vertex != -1) { adjList[i] =
//mazegraph.cpp
#include "mazegraph.h" #include
mazegraph::mazegraph() { int vertex; cin >> size; cin >> start; cin >> exit; assert(0 <= start && start < size); assert(0 <= exit && exit < size);
adjList.resize(size,NULL); for(int i = 0; i < size; ++i) { cin >> vertex; while(vertex != -1) { adjList[i] = new vnode(vertex,adjList[i]); // insert at begining cin >> vertex; }
//mazegraph.h
#ifndef MZGRPH #define MZGRPH
#include #include #include
using namespace std;
struct vnode { int v; // vertex vnode *next; vnode(int u, vnode *n): v(u), next(n){}; };
typedef vnode * vnodeptr;
class mazegraph { public: mazegraph(); // interactive constructor using cin vector adj() {return adjList;} friend stack dfsFindExit(mazegraph &M); private: int size; int start; int exit; vector adjList; };
#endif
//pathfinder.cpp
#include "pathfinder.h" #include #include
using namespace std;
stack dfsFindExit(mazegraph &M) { int start = M.start, exit = M.exit, current, nbr; stack path; vector visited(M.size,false); vnodeptr cursor; // Complete the code for this function below
}
//pathfinder.h
#include "mazegraph.h"
stack dfsFindExit(mazegraph &M);
//pathtester.cpp
#include #include "mazegraph.h" #include "pathfinder.h"
using namespace std;
void printBottomToTop(stack S)
{ if(S.empty()) return; else { int topguy = S.top(); S.pop(); printBottomToTop(S); cout << topguy << " "; } }
int main() { mazegraph M; stack wayout = dfsFindExit(M);
if(wayout.empty()) cout << "No way out" << endl; else { printBottomToTop(wayout); cout << endl; } }
//input
6 2 3 2 3 5 -1 5 3 2 4 -1 0 1 4 5 -1 0 1 5 -1 1 2 5 -1 0 1 2 3 4 -1
//correct
2 5 4 1 3
//cut_tester.cpp
#include "graph.h"using namespace std; int main(){ graph G; if(!G.connected(-1)) { cout << "Graph is not connected; terminating" << endl; return 1; } vector cutpoints = G.get_cutpoints(); cout << "Number of cutpoints: " << cutpoints.size() << endl; cout << "Cutpoints: "; for(int i = 0; i < cutpoints.size(); ++i) cout << cutpoints[i] << " "; cout << endl; return 0;}
//graph.cpp
#include "graph.h"#include
adjList[i] = new vnode(vertex,adjList[i]); // insert at begining cin >> vertex; } }} int firstFalse(vector
}
//graph.h
#ifndef GRPH#define GRPH #include
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