Question: Write a C++ function named pathExists that determines whether or not a there's a path from start to finish in a rectangular maze. Here is

 Write a C++ function named pathExists that determines whether or not

a there's a path from start to finish in a rectangular maze.

Write a C++ function named pathExists that determines whether or not a there's a path from start to finish in a rectangular maze. Here is the prototype bool pathExists (string maze[ 1, int nRows, int ncols, int sr, int sc, int er, int ec)i // Return true if there is a path from (sr, sc) to (er,ec) // through the maze; return false otherwise The parameters are sents the maze. Each string of the array is a row of the maze o A rectangular maze of Xs and dots that repre o Each"x, represents a wall, each'@' represents a bottomless trap hole, and each ' ' represents a walkway o The number of rows in the maze o The number of columns in the maze. Each string in the maze parameter must be this length o The starting coordinates in the maze: sr, sc; the row number is in the range 0 through nRows-1, and the column number is in the range 0 through nCols-1 o The ending coordinates in the maze: er, ec; the row number is in the range 0 through nRows-1, and the column number is in the range 0 through nCols-1 Here is an example of a simple maze with 5 rows and 7 columns The function must return true if in the maze as it was when the function was called, there is a path from maze[ sr[sc] to maze[er][ec] that includes only walkways no walls or bottomless trap holes; otherwise it must return false. The path may turn north, east, south, and west, but not diagonally. When the function returns, it is allowable for the maze to have been modified by the function (Our convention is that (0,0 is the northwest (upper left) corner, with south (down) being the increasing r direction and east (right) being the increasing c direction.) Here is pseudocode for vour function: If the start location is equal to the ending location, then we 've solved the maze, so return true Mark the start location as visted For each of the four directions, If the location one step in that direction (from the start location) is unvisited then call pathExists starting from that location (and ending at the same ending location as in the current call) If that returned true, then return true Return false (If you wish, you can implement the pseudocode for loop with a series of four if statements instead of a loop.) Here is how a client might use your function

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!