Preorder
preorder(N *root) { if(root) { printf("Value : [%d]", root->value); preorder(root->left); preorder(root->right); } }
Postorder
postorder(Node *root) { if(root) { postorder(root->left); postorder(root->right); printf("Value : [%d]", root->value); } }
Inorder
inorder(Node *root) { if(root) { inorder(root->left); printf("Value : [%d]", root->value); inorder(root->right); } }
Time complexity of traversals is O(n).
|
No comments:
Post a Comment