[Zope] tree traversal question

J Cameron Cooper jccooper@jcameroncooper.com
Thu, 05 Jun 2003 13:05:01 -0500


> Does any body have simple solution (python script) for tree 
> traversal(not recursive), so that i can traverse objects level by 
> level from root to bottom?

First, check ZopeLabs. (But I don't think they have that yet.)

Else, find yourself an algorithm book (or a search engine!), and look 
for a breadth-first traversal/search algorithm. It probably won't have 
anything in Python, but it should have pseudo-code (which is close) or C 
(which is translatable). Then do it, it shouldn't be hard: the algorithm 
shouldn't be but ten lines or so, and the Zope methods for getting 
children and going to children are dead easy.

Afterwards, submit your code to ZopeLabs as a recipe.

Here's some places to start:

http://www.google.com/search?hl=en&ie=ISO-8859-1&q=breadth-first+tree+traversal&btnG=Google+Search
http://www.cs.bu.edu/teaching/c/tree/breadth-first/
http://www.ics.uci.edu/~eppstein/161/960215.html

And what's wrong with recursion anyway?

          --jcc