Newbie: conventional instead of recursive way

Grant Edwards grante at visi.com
Thu Dec 19 11:19:21 EST 2002


In article <atqvnf$j5e$1 at bagan.srce.hr>, Igor Zivkovic wrote:
> Steve Holden <sholden at holdenweb.com> wrote:
> 
>> You can look as long as you like. What makes you feel that recursion is
>> "unconventional"? It's a perfectly valid technique for dealing with
>> recursive data structures, and in fact the most natural way to handle them.
>> Or is this purely an intellectual exercise? I just don't see what you hope
>> to gain by avoiding recursion.
> 
> I know that the proper way to do it is with recursion. I shouldn't 
> have called it unconventional though, sorry. Its just an exercise I can't 
> solve. I've read in some tutorial it can be done using loops but it didn't 
> give any examples and I can't figure it out on my own. I was hoping 
> someone could at least give me a hint.

IMO, recursion is the only way to do it.  You can use the
interpreter's call stack to keep track of where you are, or you
can build a stack explicitly in your program and manipulate it
inside a loop.

The latter is just simulating the former.

-- 
Grant Edwards                   grante             Yow!  Don't SANFORIZE me!!
                                  at               
                               visi.com            



More information about the Python-list mailing list