Binary Tree in C

               How To Create Binary Tree In C 

This Program introduce you how to create binary tree in C.

 

#include<stdio.h>

#include<stdlib.h>
 

typedef struct node{
 

int data;
 

struct node *left;
 

struct node *right;
 

}node;

node *create()
 

{
 

node *p;
 

int x;
 

printf("enter data(-1 for no data):");
 

scanf("%d",&x);
 

if(x==-1)
 

return NULL;
 

p=(node*)malloc(sizeof(node));
 

p->data=x;
 

printf("enter left element:%d\n",x);
 

 p->left=create();

printf("enter right element:%d\n",x);
 

p->left=create();
 

return p;
 

}
 

int main()
 

{
 

node *root;
 

root=create();
 

return 0;
 

}

Comments