0001 template <typename T> bool BTree<T>::remove(const T& e) { 0002 if (!search(e)) return false; //确认e的确存在(于_x->key[_k]) 0003 if (_x->way[0]) { //即便x不是叶子,亦可经过如下的腾挪,使之“成为”叶子 0004 BTNP<T> s = _x->way[_k+1]; //在右子树中一路向左,末端叶节点s中的首个关键码 0005 while (s->way[0]) s = s->way[0]; //就是e的后继 0006 _x->key[_k] = s->key[0]; _x = s; _k = 0; //令e与之“交换” 0007 } //至此,x必是叶节点,且e“是”其中的第k个关键码 0008 _x->key.remove(_k); _x->way.remove(); _N--; //删除e以及其下的一个外部节点 0009 solveUnderflow(); return true; //如下溢,则修复之 0010 } //remove