Binary Tree Implementation and Traversal Method Code in C
Binary Tree Implementation and Traversal Method Code in C
// Tree traversal in C
#include <stdio.h>
#include <stdlib.h>
struct node {
int item;
};
// Inorder traversal
inorderTraversal(root->left);
inorderTraversal(root->right);
// Preorder traversal
preorderTraversal(root->left);
preorderTraversal(root->right);
// Postorder traversal
postorderTraversal(root->left);
postorderTraversal(root->right);
newNode->item = value;
newNode->left = NULL;
newNode->right = NULL;
return newNode;
root->left = create(value);
return root->left;
root->right = create(value);
return root->right;
int main() {
insertLeft(root, 4);
insertRight(root, 6);
insertLeft(root->left, 42);
insertRight(root->left, 3);
insertLeft(root->right, 2);
insertRight(root->right, 33);
inorderTraversal(root);
preorderTraversal(root);
printf("\nPostorder traversal \n");
postorderTraversal(root);