Algorithm 4 Binary Tree Traversal Nonrecursive

Require: a binary tree TT

Ensure: print all keys appearing in TT

1:Let SS be a stack

2:Push(S,T.rootS, T.root)

3:while not StackEmpty(SS) do

4:x=x = Pop(SS)

5:if x==NILx == NIL then

6:continue

7:end if

8:print x.keyx.key

9:Push(x.rightx.right)

10:Push(x.leftx.left)

11:end while