Implementing preorder, inorder and postorder traversal in one pass.