0001 template <typename K, typename V> bool Skiplist<K, V>::remove ( K k ) { //跳转表词条删除算法 0002 if ( empty() ) return false; //空表情况 0003 ListNode<Quadlist<Entry<K, V>>*>* qlist = first(); //从顶层Quadlist的 0004 QuadlistNode<Entry<K, V>>* p = qlist->data->first(); //首节点开始 0005 if ( !skipSearch ( qlist, p, k ) ) return false; //目标词条不存在,直接返回 0006 do { //若目标词条存在,则逐层拆除与之对应的塔 0007 QuadlistNode<Entry<K, V>>* lower = p->below; //记住下一层节点,并 0008 qlist->data->remove ( p ); //删除当前层节点,再 0009 p = lower; qlist = qlist->succ; //转入下一层 0010 } while ( qlist->succ ); //如上不断重复,直到塔基 0011 while ( !empty() && first()->data->empty() ) //逐一地 0012 List::remove ( first() ); //清除已可能不含词条的顶层Quadlist 0013 return true; //删除操作成功完成 0014 }