+ //WeakPtr parent_;
+ //WeakPtr prevSibling_;
+ //Ptr next_;
+ //WeakPtr lastDescendant_;
+
+ subtree->remove();
+
+ Ptr firstChild = getFirstChild();
+ Ptr lastChild = getLastChild();
+ Ptr nextSibling = getNextSibling();
+ Ptr lastDescendant = getLastDescendant();
+ Ptr newLastDescendant = subtree->getLastDescendant();
+ Ptr parent = getThis();
+
+ // 1. If parent is leaf, set parent.next to subtree.
+
+ if (isLeaf())
+ {
+ next_ = subtree;
+ }
+
+ // 2. Set parent.last_descendant to subtree.last_descendant.
+
+ Ptr temp = parent;
+ while (temp && temp->getLastDescendant() == lastDescendant)
+ {
+ temp->lastDescendant_ = newLastDescendant;
+ temp = temp->getParent();
+ }
+
+ // 3. Set subtree.parent to parent.
+
+ subtree->parent_ = parent;
+
+ // 4. Set parent.first_child.prev_sibling to subtree.
+
+ if (firstChild)
+ {
+ firstChild->prevSibling_ = subtree;
+ }
+
+ // 5. Set subtree.prev_sibling to parent.last_child.
+ // 6. Set parent.last_child.last_descendant.next to subtree.
+
+ if (lastChild)
+ {
+ subtree->prevSibling_ = lastChild;
+ lastChild->getLastDescendant()->next_ = subtree;
+ }
+ else
+ {
+ subtree->prevSibling_ = subtree;
+ }
+
+ // 7. Set subtree.last_descendant.next to parent.next_sibling.
+
+ if (nextSibling)
+ {
+ subtree->getLastDescendant()->next_ = nextSibling;
+ }