Arnaud Delobelle wrote:
In that case the following would not grow the stack, given tail-call
optimization:
def visit(node):
print 'visiting', node
if node.right is None:
return visit(node.left)
if node.left is not None:
visit(node.left)
return visit(node.right)
Or (without TCO):
def visit(node):
while node is not None:
print 'visiting', node
if node.right is None:
node = node.left
else:
if node.left is not None:
visit(node.left)
node = node.right
Not so hard, really.
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list