binary tree
binary tree
#include<stdio.h>
#include<stdlib.h>
struct node
{
struct node *leftChild;
struct node *rightChild;
int data;
};
struct node *root;
if(rightChild(tree))
{
tree->rightChild = (struct node*)malloc(sizeof(struct node));
printf("Enter the data for right child: ");
scanf("%d", &tree->rightChild->data);
create(tree->rightChild);
}
else
{
tree->rightChild = NULL;
}
}
int main()
{
printf("Creating the root\n");
root = (struct node*)malloc(sizeof(struct node));
printf("Enter the data for root: ");
scanf("%d", &root->data);
create(root);
printf("Inorder traversal for the tree is\n");
inorder(root);
printf("Preorder traversal for the tree is\n");
preorder(root);
printf("Postorder traversal for the tree is\n");
postorder(root);
return 0;
}