Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please convert the following graph python code to c++ def find_next(coordinates, maze): next_coordinates = [] if coordinates[0] - 1 >= 0 and maze[coordinates[0] - 1][coordinates[1]]

please convert the following graph python code to c++

def find_next(coordinates, maze): next_coordinates = [] if coordinates[0] - 1 >= 0 and maze[coordinates[0] - 1][coordinates[1]] != 1: next_coordinates.append((coordinates[0] - 1, coordinates[1])) if coordinates[0] + 1 < len(maze) and maze[coordinates[0] + 1][coordinates[1]] != 1: next_coordinates.append((coordinates[0] + 1, coordinates[1])) if coordinates[1] + 1 < len(maze[0]) and maze[coordinates[0]][coordinates[1] + 1] != 1: next_coordinates.append((coordinates[0], coordinates[1] + 1)) if coordinates[1] - 1 >= 0 and maze[coordinates[0]][coordinates[1] - 1] != 1: next_coordinates.append((coordinates[0], coordinates[1] - 1)) return next_coordinates

def dfs(maze, stack, visited): start = (0, 0) goal = (3, 2) stack.append(start) while stack: print(" ") n = stack.pop() print(f"Popping {n}") print(f"Is {n} my goal?") if n == goal: print("DONE!") return print(f"No.") next_steps = find_next(n, maze) print(f"Next Steps: {next_steps}") for x in next_steps: print(f"Evaluating {x}") if x in visited: print(f"{x} already visited, skipping...") continue visited.add(x) stack.append(x) print(f"Visited nodes: {visited}") print(f"Stack: {stack}")

def main(): stack = [] visited = set() maze = [[0, 1, 1, 0], [0, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 0]] dfs(maze, stack, visited)

if __name__ == "__main__": main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Databases questions

Question

Brief the importance of span of control and its concepts.

Answered: 1 week ago

Question

What is meant by decentralisation?

Answered: 1 week ago

Question

Write down the Limitation of Beer - Lamberts law?

Answered: 1 week ago

Question

Discuss the Hawthorne experiments in detail

Answered: 1 week ago

Question

What is level mixed-model sequencing and why is it important?

Answered: 1 week ago

Question

To what extent has technology had an impact on JIT/lean systems?

Answered: 1 week ago