Answer: PROCEDURE PREORDER(T)
[Given a binary tree whose root node address is given by the pointer variable T, this algorithm traverses the tree in preorder in an iterative manner].
1. [Initialize]
If T = NULL
then write (“Empty Tree”)
return
else
TOP <-- 0.
2. [Process each stack branch address]
Repeat step 3 while TOP > 0.
3. [Get stored address and branch left]
flag <-- 0
while T != NULL
while flag != 1
call push(S,TOP,T)
write DATA(D)
T <-- LPTR(T)
if T = NULL
flag <-- 1.
4. [Traverse the right side]
D <-- pop(S,TOP)
T <-- RPTR(D)
flag <-- 0
while T =NULL
D <-- POP(S,TOP)
T <-- RPTR(D)
if TOP = 0
return.
5. [FINISH]
return.