0001 template <typename T> Rank List<T>::dedup() { 0002 Rank oldSize = _size; ListNodePosi<T> p = first(); 0003 for ( Rank r = 0; p != tail; p = p->succ ) //O(n) 0004 if ( ListNodePosi<T> q = find(p->data, r, p) ) 0005 remove(q); //此时q与p相等,但删除前者更为简明 0006 else r++; //r为无重前缀的长度 0007 return oldSize - _size; //删除元素总数 0008 }