-
Notifications
You must be signed in to change notification settings - Fork 76
/
Tree.c
79 lines (59 loc) · 1015 Bytes
/
Tree.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *left;
struct node *right;
};
typedef struct node nodep;
nodep *root;
nodep *insert()
{
int x;
nodep *new=(struct node*)malloc(sizeof(struct node));
printf("\n ENter the data (-1 for exit) : ");
scanf("%d",&x);
if(x==-1)
return NULL;
new->data=x;
printf("\n Enter the Left node :");
new->left=insert();
printf("\n Enter the Right Node :");
new->right=insert();
return new;
}
void printtree()
{
}
nodep del(nodep *top)
{
if(top!=NULL)
{
del(top->left);
printf("\t %d",top->data);
del(top->right);
}
}
int main()
{
//nodep *root;
char ch;
while(1)
{
printf("\n Enter your choice :");
printf("\n 1.Insert ");
printf("\n 2.Delete ");
printf("\n 3.Print");
printf("\n Anything to exit");
scanf("%d",&ch);
if(ch==1)
root=insert();
else if(ch==2)
del(root);
else if(ch==3)
printtree();
else
exit(0);
}
}