void leftRotate(Bnode parent, int position) { Bnode left = parent.children[position]; Bnode right = parent.children[position + 1]; int newPosition = left.insert(parent.keys[position]); moveParent(left, newPosition + 1, right.children[0]); parent.keys[position] = right.keys[0]; right.children[0] = right.children[1]; right.delete(0); }
Bnode merge(Bnode parent, int position) { Bnode left = parent.children[position]; Bnode right = parent.children[position + 1]; int newPosition = left.insert(parent.keys[position]); moveParent(left, newPosition + 1, right.children[0]); for (int i = 0; i < right.n; i++) { newPosition = left.insert(right.keys[i]); moveParent(left, newPosition + 1, right.children[i + 1]); } parent.delete(position); return(left); }