Question 7 : 1D Maze 10 points Suppose you're given a 1D maze in an array of chars called 'maze'. The variable 'size' contains the number of chars in the array. You can move left or right one char. The char 'X' represents impassible space. Any other char can be passed through either forward or backward). The char 'S' is the starting point and 'F' is the finish point. Example: X S F. X X This puzzle is fairly boring so we add one more complication. The digits {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} represent warp zones. In addition to the usual left and right movement these chars allow you to move to the matching digit (if present, a digit will appear exactly 2 times). Below is an example maze: X S 1 2 X F 2 X X 1 3 3 X х Convert a given 1D array to an equivalent graph. There should be a solution to the maze if and only if there is a path through the graph between the start and finish vertices. You can assume the first and last positions of the maze contain the char *X'. In addition to returning a graph, you should also store the index of the start and finish into the locations pointed to by 'ps' and 'pf'. Some helpful functions/reminders: //Creates and returns a new empty Graph Graph* createGraph(); // Adds an edge from vertex 'from' to vertex 'to'. //If needed also automatically creates vertices to represent the given integers. void addEdge Graph *g, int from, int to ); char = int "O' = 48 '1' = 49 : '9' = 57 You can compare char values directly with ints or just use the function is Digit() to test if a given char is a digit.
Complete the following function: Graph* mazeToGraph( char* maze, int size, int *ps, int *pf ){ //Declare variables //Build the graph 1/Return the requested data (be sure you also set 'ps' and 'pf' earlier): return }
Question 7 : 1D Maze 10 points Suppose you're given a 1D maze in an array of chars called 'maze'. The variable 'size' co
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Question 7 : 1D Maze 10 points Suppose you're given a 1D maze in an array of chars called 'maze'. The variable 'size' co
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!