@@ -262,36 +262,32 @@ struct node* insertN(int value,struct node *root,struct node *parent){
262
262
263
263
264
264
} 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 ){
267
274
// Find the parent of the current left and right box
268
275
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 ;
273
280
274
281
printf ("Left half is: %d\n" ,ss -> leftHalf -> value [0 ]);
275
282
printf ("Right half is: %d\n" ,ss -> rightHalf -> value [0 ]);
276
283
277
- ss -> leftHalf -> parent = parent ;
278
- ss -> rightHalf -> parent = parent ;
284
+ ss -> leftHalf -> parent = position -> box -> parent ;
285
+ ss -> rightHalf -> parent = position -> box -> parent ;
279
286
break ;
280
287
}
281
288
}
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
+ }
295
291
296
292
return ss -> leftHalf ;
297
293
}
0 commit comments