LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Find the path to the exit (C code) (http://www.linuxquestions.org/questions/programming-9/find-the-path-to-the-exit-c-code-508315/)

linuxlover1 12-07-2006 02:58 PM

Find the path to the exit (C code)
 
Hello to all....!
The problem is ... i am trying to solve the below problem...

####$#
#-##--
#---#-
#-#-#-
##^---
##-##-

'#': wall , '-': free path , '$':the exit , '^': the man

Well...i have to program the man to find the exit from the 2D maze.....but the alogorithm must not use recursion.....
Any ideas.. ?? I do not know Graph theory...and stuff like Link-lists...stucks or queues.....I need to solve this just with arrays and no recursion.

The Output:

####$#
#-## | |
#---# |
#-#-# |
##^| | |
##-##-

"|" : the steps to the exit.

Please help...Thanks in advance !!

matthewg42 12-07-2006 04:41 PM

please repost your ascii art in [code] tags.

taylor_venable 12-07-2006 09:09 PM

Iteration and recursion are two sides of the same coin. Anything one can do, the other can do. One way to approach this problem, if recursion seems natural to you, is to write a recursive solution and convert it to iteration. (Usually this means converting the automatic state of the program's stack into explicit state within a loop.)

matthewg42 12-07-2006 09:43 PM

There are lots of path finding algorithms. One of the simpler to implement is Dijkstra's Algorithm. It's not very efficient though.

For a really good discussion of path finding algorithms, have a look at this extremely good site.


All times are GMT -5. The time now is 12:28 AM.