Skip to content

Commit 6c7d3c8

Browse files
author
Raven G. Duran
committed
Added Initial Insert and Creat node functions
1 parent 8c6c1d1 commit 6c7d3c8

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

btree.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
#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;
211

312
// Menu functions
413
void showMenu();
@@ -7,6 +16,10 @@ void doDelete();
716
void doSearch();
817
void doInOrder();
918

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+
1023

1124
int main(){
1225
showMenu();
@@ -15,6 +28,7 @@ int main(){
1528
return 0;
1629
}
1730

31+
// Menus
1832
void showMenu(){
1933
system("cls");
2034
printf(" _____ _____ \n");
@@ -39,9 +53,16 @@ void showMenu(){
3953
}
4054

4155
void doInsert(){
56+
int value;
57+
4258
system("cls");
4359
printf("--- Insertion ---\n");
60+
printf("Value: ");
61+
scanf("%d",&value);
4462

63+
tRoot = insertN(value,tRoot,tRoot);
64+
65+
printf("Press any key to continue...\n");
4566
getch();
4667
showMenu();
4768
}
@@ -50,6 +71,7 @@ void doDelete(){
5071
system("cls");
5172
printf("--- Deletion ---\n");
5273

74+
printf("Press any key to continue...\n");
5375
getch();
5476
showMenu();
5577
}
@@ -58,14 +80,34 @@ void doSearch(){
5880
system("cls");
5981
printf("--- Search ---\n");
6082

83+
printf("Press any key to continue...\n");
6184
getch();
6285
showMenu();
6386
}
6487

6588
void doInOrder(){
6689
system("cls");
6790
printf("--- Printing ---\n");
91+
printf("%d\n",tRoot->value[0]);
6892

93+
printf("Press any key to continue...\n");
6994
getch();
7095
showMenu();
7196
}
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+

btree.exe

229 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)