left -> parent -> right
INORDER-TREE-WALK (x)
if x!= NIL
INORDER-TREE-WALK (x, left)
print x.key
INORDER-TREE-WALK (x, right)
void inOrder(struct Node *root)
{
stack<Node *> s;
Node *curr = root;
while (curr != NULL || s.empty() == false)
{
/* Reach the left most Node of the
curr Node */
while (curr != NULL)
{
/* place pointer to a tree node on
the stack before traversing
the node's left subtree */
s.push(curr);
curr = curr->left;
}
/* Current must be NULL at this point */
curr = s.top();
s.pop();
cout << curr->data << " ";
/* we have visited the node and its
left subtree. Now, it's right
subtree's turn */
curr = curr->right;
} /* end of while */
}
t = tree.Root;
while (true) {
while (t.Left != t.Right) {
while (t.Left != null) { // Block one.
t = t.Left;
Visit(t);
}
if (t.Right != null) { // Block two.
t = t.Right;
Visit(t);
}
}
while (t != tree.Root && (t.Parent.Right == t || t.Parent.Right == null)) {
t = t.Parent;
}
if (t != tree.Root) { // Block three.
t = t.Parent.Right;
Visit(t);
} else {
break;
}
}
parent -> left -> right
PREORDER-TREE-WALK (x)
if x!= NIL
print x.key
PREORDER-TREE-WALK (x, left)
PREORDER-TREE-WALK (x, right)
left -> right -> parent
POSTORDER-TREE-WALK (x)
if x!= NIL
POSTORDER-TREE-WALK (x, left)
POSTORDER-TREE-WALK (x, right)
print x.key