Algorithm Maze (maze, start)
Find the goal in a maze using a stack (depth first search)
create an empty stack named S;
push start onto S;
while S is not empty do
current pop from S;
if current is the goal then
output “Success!”;
S empty stack; {to end the loop}
else if current is not a wall and current is not marked as visited then
mark current as visited;
push onto S the point to the right of current;
push onto S the point to the left of current;
push onto S the point above current;
push onto S the point below current;
end if
end while
No comments:
Post a Comment