[Python-de] Re: [Python-de] Kleine Aufgabe, große Wirkung
Tomek Meka
tmeka at gmx.net
Sun Apr 6 22:21:11 EDT 2003
> Nicht übel. Jetzt muß man nur noch erkennen, daß es
> sich um eine Tail-Rekursion handelt und man es mit
> einer einfachen Schleife kürzer und nicht-rekursiv
> schafft.
Die Aufgabe war wirklich nicht schwierig, eine nichtrekursive Loesung:
>>> def traverse(root, count):
list = [ root ]
while list and count:
val, child1, child2 = list[0]
del list[0]
print val
count = count - 1
if child1 is not None:
list.append(child1)
if child2 is not None:
list.append(child2)
Es waere aber sehr schoen, wenn python automatisch tail-rekursion erkennen
koennte :-)
Gruesse,
Tomek
--
+++ GMX - Mail, Messaging & more http://www.gmx.net +++
Bitte lächeln! Fotogalerie online mit GMX ohne eigene Homepage!
More information about the Python-de
mailing list