Skip to content

Commit 20af300

Browse files
author
Raven G. Duran
committed
Starting To Debug 3+ levels
1 parent d36c118 commit 20af300

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

btree.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ void doInsert(){
7171
system("cls");
7272
printf("--- Insertion ---\n");
7373
printf("Value: ");
74-
scanf("%d",&value);
74+
scanf("%d",&value);
7575

7676
tRoot = insertN(value,tRoot,NULL);
7777

@@ -147,14 +147,16 @@ struct node* insertN(int value,struct node *root,struct node *parent){
147147
printf("Data Already inserted!\n");
148148
break;
149149
} else if ( value > root->value[i] ){ // if value to be inserted is greater, then proceed to next box
150-
if (root->keys[i+1] != NULL && root->keys[i+1]->keyCount < treeOrder + 1) {
150+
if (root->keys[i+1] != NULL && root->keys[i+1]->keyCount < treeOrder + 1 && root->value[i+1] > value) {
151+
PUT_RIGHT:
151152
root->keys[i+1] = insertN(value,root->keys[i+1],root);
152153
break;
153154
} else i++;
154155

155156
continue;
156157
} else { // This is if the value to be inserted is lesser which means, we can put it now
157158
if (root->keys[i] != NULL && root->keys[i]->keyCount < treeOrder + 1) {
159+
PUT_LEFT:
158160
root->keys[i] = insertN(value,root->keys[i],root);
159161
break;
160162
} else {
@@ -171,6 +173,11 @@ struct node* insertN(int value,struct node *root,struct node *parent){
171173

172174
}
173175
} else { // else if the box is null or the last box. Insert directly
176+
if (root->keys[i] != NULL && root->keys[i]->keyCount < treeOrder + 1) {
177+
printf("Succes!\n");
178+
goto PUT_LEFT;
179+
}
180+
174181
root->value[i] = value;
175182
root->keyCount++;
176183

btree.exe

512 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)