void removeFromSubTree(TreeNode* &node,int value) { if (node == NULL) printf("no such an element."); else if (node -> value == value ) { if((isLeaf(node))||(hasOneChild(node))) { if (isLeaf(node)) { delete node; node = NULL; return; } if (hasOneChild(node)) { if(hasLeftChild(node)) { TreeNode* tmp = node->left; delete node; node = tmp; } else { TreeNode* tmp = node->right; delete node; node = tmp; } } } else { int tmp = popMostLeftValue(node->right); node->value = tmp; } } else if (value > node->value) return removeFromSubTree(node->right,value); else return removeFromSubTree(node->left,value); }
static void replaceChildrenWithText(HTMLElement* element, const String& text, ExceptionCode& ec) { if (hasOneTextChild(element)) { static_cast<Text*>(element->firstChild())->setData(text, ec); return; } RefPtr<Text> textNode = new Text(element->document(), text); if (hasOneChild(element)) { element->replaceChild(textNode.release(), element->firstChild(), ec); return; } element->removeChildren(); element->appendChild(textNode.release(), ec); }
static void replaceChildrenWithFragment(HTMLElement* element, PassRefPtr<DocumentFragment> fragment, ExceptionCode& ec) { if (!fragment->firstChild()) { element->removeChildren(); return; } if (hasOneTextChild(element) && hasOneTextChild(fragment.get())) { static_cast<Text*>(element->firstChild())->setData(static_cast<Text*>(fragment->firstChild())->string(), ec); return; } if (hasOneChild(element)) { element->replaceChild(fragment, element->firstChild(), ec); return; } element->removeChildren(); element->appendChild(fragment, ec); }
static inline bool hasOneTextChild(ContainerNode* node) { return hasOneChild(node) && node->firstChild()->isTextNode(); }