vze4rx4y at verizon.net
Wed Feb 19 23:59:09 CET 2003
> Just occurs to me that if I can somehow pass in an argument to specify
> a special ordering when traversing a tree, that'll be perfect.
Python's own solution to this problem is to use a different method
for each type of iterator:
Alternatively, you can create a method with a parameter.
Don't use __iter__() for this since it is already defined with
no parameters; instead, try something like: traverse(ordering).
Using generators are a clean way to return an iterator whose next()
method obeys the ordering:
. . .
"Untested psuedocode approximation of what you want"
if order == INORDER:
elif order == PREORDER:
. . .
More information about the Python-list