1
1
#include <stdio.h>
2
+ #define MAX 100
3
+
4
+ // B-Tree Node Structure
5
+ struct node {
6
+ int value [MAX ];
7
+ struct node * keys [MAX + 1 ];
8
+ struct node * parent ;
9
+ int keyCount ;
10
+ } * tRoot = NULL ;
2
11
3
12
// Menu functions
4
13
void showMenu ();
@@ -7,6 +16,10 @@ void doDelete();
7
16
void doSearch ();
8
17
void doInOrder ();
9
18
19
+ // Tree Operations
20
+ struct node * newNode (int value ,struct node * parent );
21
+ struct node * insertN (int value ,struct node * root ,struct node * parent );
22
+
10
23
11
24
int main (){
12
25
showMenu ();
@@ -15,6 +28,7 @@ int main(){
15
28
return 0 ;
16
29
}
17
30
31
+ // Menus
18
32
void showMenu (){
19
33
system ("cls" );
20
34
printf (" _____ _____ \n" );
@@ -39,9 +53,16 @@ void showMenu(){
39
53
}
40
54
41
55
void doInsert (){
56
+ int value ;
57
+
42
58
system ("cls" );
43
59
printf ("--- Insertion ---\n" );
60
+ printf ("Value: " );
61
+ scanf ("%d" ,& value );
44
62
63
+ tRoot = insertN (value ,tRoot ,tRoot );
64
+
65
+ printf ("Press any key to continue...\n" );
45
66
getch ();
46
67
showMenu ();
47
68
}
@@ -50,6 +71,7 @@ void doDelete(){
50
71
system ("cls" );
51
72
printf ("--- Deletion ---\n" );
52
73
74
+ printf ("Press any key to continue...\n" );
53
75
getch ();
54
76
showMenu ();
55
77
}
@@ -58,14 +80,34 @@ void doSearch(){
58
80
system ("cls" );
59
81
printf ("--- Search ---\n" );
60
82
83
+ printf ("Press any key to continue...\n" );
61
84
getch ();
62
85
showMenu ();
63
86
}
64
87
65
88
void doInOrder (){
66
89
system ("cls" );
67
90
printf ("--- Printing ---\n" );
91
+ printf ("%d\n" ,tRoot -> value [0 ]);
68
92
93
+ printf ("Press any key to continue...\n" );
69
94
getch ();
70
95
showMenu ();
71
96
}
97
+
98
+ // Operations
99
+ struct node * newNode (int value ,struct node * parent ){
100
+ struct node * root = (struct node * )malloc (sizeof (struct node ));
101
+ root -> value [0 ] = value ;
102
+ root -> keyCount = 2 ;
103
+ root -> parent = parent ;
104
+
105
+ return root ;
106
+ }
107
+
108
+ struct node * insertN (int value ,struct node * root ,struct node * parent ){
109
+ if (root == NULL ){
110
+ return newNode (value ,parent );
111
+ }
112
+ }
113
+
0 commit comments