-
Notifications
You must be signed in to change notification settings - Fork 0
/
YourFile.c
106 lines (71 loc) · 1.48 KB
/
YourFile.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
101
102
103
104
105
106
#include <string.h>
#include <ctype.h>
#include "bintreesim.h"
//#include "bst.c"
#include "avl.c"
main()
{
char ch;
int x;
tree *bst=0;
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\
6) L to rotate left around root\n\
7) R to rotate right around root\n\
8) B to balance root\n\
");
while((ch=toupper(getch())) != 'Q')
{
switch(ch)
{
case 'I' :
printf("Enter a no.");
scanf("%d",&x);
insertavl(&bst,x);
break;
case 'D' :
printf("Enter a no. to delete : ");
scanf("%d",&x);
delnodeavl(&bst,x);
printf("Deleted\n");
break;
case 'P' :
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;
case 'L' :
lrotate(&bst);
break;
case 'R' :
rrotate(&bst);
break;
case 'B' :
bnode(&bst);
break;
}
redraw();
}
}