Question
Only allow to fill in the missing code for the function vector maze::bfs() : Test Input and Correct Output Note: the order of the vertices
Only allow to fill in the missing code for the function vector
Test Input and Correct Output
Note: the order of the vertices in the adjacency lists will be the reverse of the order in which they appear in the input file because they are inserted at the front of the list.
Input:
6
2
3
2 3 5 -1
2 3 4 5 -1
0 1 4 5 -1
0 1 5 -1
1 2 5 -1
0 1 2 3 4 -1
Correct Output
2 5 3
#include
using namespace std;
struct vnode { int v; // vertex vnode *next; vnode(int u, vnode *n) {v=u; next=n;} };
typedef vnode * vnodeptr;
class maze { public: maze(); // interactive constructor using cin void print_dfs_exitpath(); void print_bfs_exitpath(); private: int size; int start; int exit; vector
void printBottomToTop(stack
void printBottomToTop(stack
void printPredecessorPath(vector
maze::maze() { 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) { if(vertex == i) { cerr << "Invalid adjacency; terminating" << endl; assert(vertex != i); } adjList[i] = new vnode(vertex,adjList[i]); // insert at begining cin >> vertex; } } }
stack
void maze::print_dfs_exitpath() { stack
void maze::print_bfs_exitpath() { vector
vector
int main() { maze RatHaus; RatHaus.print_bfs_exitpath(); cout << endl; return 0; }
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