0001 template <typename T> //将S当作节点x的左子树接入二叉树,S本身置空 0002 BinNodePosi<T> BinTree<T>::attach ( BinTree<T>* &S, BinNodePosi<T> x ) { //x->lc == NULL 0003 if ( x->lc = S->_root ) x->lc->parent = x; //接入 0004 _size += S->_size; updateHeightAbove ( x ); //更新全树规模与x所有祖先的高度 0005 S->_root = NULL; S->_size = 0; release ( S ); S = NULL; return x; //释放原树,返回接入位置 0006 } 0007 0008 template <typename T> //将S当作节点x的右子树接入二叉树,S本身置空 0009 BinNodePosi<T> BinTree<T>::attach ( BinNodePosi<T> x, BinTree<T>* &S ) { //x->rc == NULL 0010 if ( x->rc = S->_root ) x->rc->parent = x; //接入 0011 _size += S->_size; updateHeightAbove ( x ); //更新全树规模与x所有祖先的高度 0012 S->_root = NULL; S->_size = 0; release ( S ); S = NULL; return x; //释放原树,返回接入位置 0013 }