non-recursive preorder and postorder of trees