Skip to content

Commit b84b724

Browse files
author
Raven G. Duran
committed
Just a little more bugs for insertion
1 parent 9b40bf8 commit b84b724

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
@@ -106,7 +106,6 @@ void doInOrder(){
106106
system("cls");
107107
printf("--- Printing ---\n");
108108

109-
//for (i = 0; i < tRoot->keyCount - 1; i++) printf("%d ", tRoot->value[i]);
110109
if (tRoot != NULL) inOrder(tRoot);
111110
else printf("\nThe tree is empty!\n");
112111

@@ -219,15 +218,23 @@ struct node* insertN(int value,struct node *root,struct node *parent){
219218
parent->keys[0] = leftHalf;
220219
parent->keys[1] = rightHalf;
221220

222-
free(tempRoot); // Delete old root node box
221+
//free(tempRoot); // Delete old root node box
223222
return parent;
224223
} else {
225224
for (i = 0; i < parent->keyCount; i++){
226225
if (parent->keys[i] == tempRoot){
227226
parent->keys[i] = leftHalf;
228227
parent->keys[i+1] = rightHalf;
228+
} else if (parent->keys[i] != NULL) {
229+
for (j = 0; j < parent->keys[i]->keyCount; j++){
230+
if (parent->keys[i]->keys[j] == tempRoot){
231+
parent->keys[i]->keys[j] = leftHalf;
232+
parent->keys[i]->keys[j+1] = rightHalf;
233+
}
234+
}
229235
}
230236
}
237+
231238
free(tempRoot);
232239
return leftHalf;
233240
}

btree.exe

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)