Suppose you're given a 1D maze in an array of chars called 'maze'. The variable ‘size' contains the number of chars in t
Posted: Sat May 14, 2022 8:20 pm
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 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 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(); 1/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 '0' = 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 //Return the requested data (be sure you also set 'ps' and 'pf' earlier): return }
Complete the following function: Graph* mazeToGraph( char* maze, int size, int *ps, int *pf ){ //Declare variables //Build the graph //Return the requested data (be sure you also set 'ps' and 'pf' earlier): return }