Preorder with stack

Hide text Hide pseudo-code

Traverse the following binary tree in preorder. Show the contents of the traversal's stack as the algorithm progresses.

Some additional problems.

PreOrderTreeTraversal(root)
1  S.push(root)
2  while (S.notEmpty()) do
3    next = S.pop()
4    visit(next)
5    if (next->right != NULL)
       S.push(next->right)
6    if (next->left != NULL)
       S.push(next->left)


  Created Fri Oct 30 13:52:50 EET 2009 - Powered by SVG-hut