-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test_bst.c
100 lines (66 loc) · 1.58 KB
/
Test_bst.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <string.h>
#include <ctype.h>
#include "bst.c"
main()
{
char ch;
int x;
tree *bst=0;
/*
for(i=0;i<5;i++)
insertbst(&bst,rand()%100);
delnode(&bst,34);
preorder(bst); printf("\b\b \n");
inorder(bst); printf("\b\b \n");
postorder(bst); printf("\b\b \n");
printf("%d\n",min(bst)->d);
//printf("%d\n",search(bst,34)->d);
*/
init(&bst);
printf("\nEnter :-\n\
1) I to insert\n\
2) D to delete\n\
3.a) R for preorder traverse \n\
3.b) N for inorder traverse \n\
3.c) O for postorder traverse \n\
4) F to find an element\n\
5) ctrl+c or Q to exit\n\
");
while((ch=toupper(getchar())) != 'Q')
{
switch(ch)
{
case 'I' :
printf("Enter a no.");
scanf("%d",&x);
insertbst(&bst,x);
break;
case 'D' :
printf("Enter a no.");
scanf("%d",&x);
delnode(&bst,x);
break;
case 'R' :
printf("The preorder traversal is :- ");
preorder(bst);
printf("\b\b \n");
break;
case 'N' :
printf("The inorder traversal is :- ");
inorder(bst);
printf("\b\b \n");
break;
case 'O' :
printf("The postorder traversal is :- ");
postorder(bst);
printf("\b\b \n");
break;
case 'F' :
printf("Enter a no.");
scanf("%d",&x);
printf("The element is %s found\n",search(bst,x)?"\b":"not");
break;
}
redraw();
}
}