@@ -272,31 +272,35 @@ namespace alg {
272
272
}
273
273
274
274
// case 2c:
275
- // Otherwise, if both y and ´ have only t 2 1 keys,
276
- // merge k and all of ´ into y, so that x loses both k and the
277
- // pointer to ´ , and y now contains 2t c 1 keys.
278
- // Then free ´ and recursively delete k from y.
275
+ // Otherwise, if both y and z have only t- 1 keys,
276
+ // merge k and all of z into y, so that x loses both k and the
277
+ // pointer to z , and y now contains 2t - 1 keys.
278
+ // Then free z and recursively delete k from y.
279
279
if (y->n == T-1 && z->n == T-1 ) {
280
280
// merge k & z into y
281
281
y->key [y->n ] = k;
282
282
283
283
int j;
284
- for (j=0 ;j<z->n ;j++) { // merge n keys, k already in
284
+ for (j=0 ;j<z->n ;j++) { // merge keys of z
285
285
y->key [y->n +j+1 ] = z->key [j];
286
286
}
287
- for (j=0 ;j<z->n +1 ;j++) { // merge n+1 childs
288
- y->c [y->n +j+1 ] = z->key [j];
287
+ for (j=0 ;j<z->n +1 ;j++) { // merge childs of z
288
+ y->c [y->n +j+1 ] = z->c [j];
289
289
}
290
- // mark free this node
290
+
291
+ // mark free z
291
292
z->flag |= MARKFREE;
292
293
y->n = y->n + z->n + 1 ; // size after merge
293
294
WRITE (z.get ());
294
295
WRITE (y.get ());
295
296
296
- // shift x
297
- for (j=i;j<x->n -1 ;j++) {
297
+ for (j=i;j<x->n -1 ;j++) { // delete k from node x
298
298
x->key [i] = x->key [i+1 ];
299
299
}
300
+
301
+ for (j=i+1 ;j<x->n ;j++){ // delete pointer to z --> (i+1)th
302
+ x->c [i] = x->c [i+1 ];
303
+ }
300
304
x->n = x->n - 1 ;
301
305
WRITE (x);
302
306
0 commit comments