vendredi 28 mai 2010

Given a binary tree, print out the elements in order. Without recursion.


L = [node]
do{
nextLevel=[]
while L is not empty:
n = pop(L)
print n.val
if n.left
nextLevel.add(n.left)
if n.right
nextLevel.add(n.right)
L=nextLevel
} while (nextLevel is not empty)

Aucun commentaire:

Enregistrer un commentaire