File tree Expand file tree Collapse file tree 1 file changed +19
-18
lines changed Expand file tree Collapse file tree 1 file changed +19
-18
lines changed Original file line number Diff line number Diff line change @@ -411,16 +411,9 @@ namespace alg {
411
411
412
412
// remove key[i] from x and also the child
413
413
// shrink the size & set the child-0 to left
414
- int j;
415
- for (j=i;j<x->n -1 ;j++) {
416
- x->key [j] = x->key [j+1 ];
417
- }
418
-
419
- for (j=i+1 ;j<x->n ;j++) {
420
- x->c [j] = x->c [j+1 ];
421
- }
422
- x->n = x->n - 1 ;
414
+ delete_i (x, i);
423
415
416
+ int j;
424
417
// append x.c[i] into left sibling
425
418
for (j=0 ;j<ci->n ;j++) {
426
419
left->key [left->n + j] = ci->key [j];
@@ -450,16 +443,9 @@ namespace alg {
450
443
ci->n = ci->n + 1 ;
451
444
// remove key[i] from x and also the child
452
445
// shrink the size & set the child-0 to ci
453
- int j;
454
- for (j=i;j<x->n -1 ;j++) {
455
- x->key [j] = x->key [j+1 ];
456
- }
457
-
458
- for (j=i+1 ;j<x->n ;j++) {
459
- x->c [j] = x->c [j+1 ];
460
- }
461
- x->n = x->n - 1 ;
446
+ delete_i (x, i);
462
447
448
+ int j;
463
449
// append right sibling into x.c[i]
464
450
for (j=0 ;j<right->n ;j++) {
465
451
ci->key [ci->n + j] = right->key [j];
@@ -490,6 +476,21 @@ namespace alg {
490
476
}
491
477
}
492
478
479
+ /* *
480
+ * delete ith node
481
+ */
482
+ void delete_i (node x, int32_t i) {
483
+ int j;
484
+ for (j=i;j<x->n -1 ;j++) {
485
+ x->key [j] = x->key [j+1 ];
486
+ }
487
+
488
+ for (j=i+1 ;j<x->n ;j++) {
489
+ x->c [j] = x->c [j+1 ];
490
+ }
491
+ x->n = x->n - 1 ;
492
+ }
493
+
493
494
/* *
494
495
* Load the root block
495
496
*/
You can’t perform that action at this time.
0 commit comments