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 {
411411
412412// remove key[i] from x and also the child
413413// 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);
423415
416+ int j;
424417// append x.c[i] into left sibling
425418for (j=0 ;j<ci->n ;j++) {
426419left->key [left->n + j] = ci->key [j];
@@ -450,16 +443,9 @@ namespace alg {
450443ci->n = ci->n + 1 ;
451444// remove key[i] from x and also the child
452445// 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);
462447
448+ int j;
463449// append right sibling into x.c[i]
464450for (j=0 ;j<right->n ;j++) {
465451ci->key [ci->n + j] = right->key [j];
@@ -490,6 +476,21 @@ namespace alg {
490476}
491477}
492478
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+
493494/* *
494495 * Load the root block
495496 */
You can’t perform that action at this time.
0 commit comments