Pre Order traversal - Recursive and Iterative solution
Example
Consider the tree:
div class="separator” style="clear: both; text-align: center;“>
To traverse a binary tree in Preorder, following operations are carried-out (i) Visit the root, (ii) Traverse the left subtree, and (iii) Traverse the right subtree.
Therefore, the Preorder traversal of the above tree will outputs:
7, 1, 0, 3, 2, 5, 4, 6, 9, 8, 10
Recursive solution
preorder(N \*root) { if(root) { printf("Value : ", root->value); preorder(root->left); preorder(root->right); } } Iterative solution
[Read More]