Skip to content

Commit 14cf0cf

Browse files
author
Raven G. Duran
committed
Almost done, fixing multilevel bugs
1 parent 83beea4 commit 14cf0cf

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

btree.c

+17-21
Original file line numberDiff line numberDiff line change
@@ -262,36 +262,32 @@ struct node* insertN(int value,struct node *root,struct node *parent){
262262

263263

264264
} else {
265-
// put left half properly
266-
if (ss != NULL){
265+
// put left and right half properly
266+
int max = findMax(ss->leftHalf); // Max of left half
267+
struct nodePosition *position = searchNValue(max,tRoot);
268+
269+
if (position != NULL){
270+
printf("Left half Max %d is Found at key: %d\n",max,position->key);
271+
}
272+
273+
if (ss != NULL && position != NULL){
267274
// Find the parent of the current left and right box
268275
int max = findMax(ss->leftHalf);
269-
for (i = 0; i < parent->keyCount; i++){
270-
if (max < parent->value[i]){
271-
parent->keys[i] = ss->leftHalf;
272-
parent->keys[i+1] = ss->rightHalf;
276+
for (i = 0; i < position->box->parent->keyCount; i++){
277+
if (position->box->parent->keys[i] == position->box){
278+
position->box->parent->keys[i] = ss->leftHalf;
279+
position->box->parent->keys[i+1] = ss->rightHalf;
273280

274281
printf("Left half is: %d\n",ss->leftHalf->value[0]);
275282
printf("Right half is: %d\n",ss->rightHalf->value[0]);
276283

277-
ss->leftHalf->parent = parent;
278-
ss->rightHalf->parent = parent;
284+
ss->leftHalf->parent = position->box->parent;
285+
ss->rightHalf->parent = position->box->parent;
279286
break;
280287
}
281288
}
282-
}
283-
284-
/**
285-
for (i = 0; i < parent->keyCount; i++){
286-
if (parent->keys[i] != NULL && parent->keys[i] == tempRoot){
287-
parent->keys[i] = leftHalf;
288-
parent->keys[i+1] = rightHalf;
289-
290-
leftHalf->parent = parent;
291-
rightHalf->parent = parent;
292-
}
293-
}
294-
**/
289+
290+
}
295291

296292
return ss->leftHalf;
297293
}

btree.exe

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)