Tree Traversals


Binary Search Trees


Eg. M,D,P,B,N,Z,O,A,C
                    M
                  /   \
                 D     P
               /      / \
              B      N   Z
            /  \      \
           A    C      O
preorder traversal = M,D,B,A,C,P,N,O,Z
inorder traversal = A,B,C,D,M,N,O,P,Z
postorder traversal = A,C,B,D,O,N,Z,P,M

An inorder traversal will visit each node of the tree by ascending order of the node data.

We require a pointer variable to hold the address of the root node. 
                 node *root = 0;   // empty tree
All other nodes are accessed by traversing the tree until they are located.

eg. non empty tree.

Using a binary search tree


About Me         Back      Home        Mail to me
Hosted by www.Geocities.ws

1