template
voidSortBTree
{
if(p == NULL) cout << "There isnot this node." < else if(p->lchild == NULL) p =p->rchild; else { BTreeNode //记录左子树中序遍历的最后一个结点(值最大的点) while(temp->rchild != NULL) temp = temp->rchild; //删除这个结点,等价于用这个结点的做子树代替这个结点(因为这个结点没有右子树) BTreeNode parent = temp; while(parent->rchild != NULL) { parent = temp; temp = temp->rchild; } parent = temp->lchild; p->set_data(temp->data); } } //deletea data template voidSortBTree { if(root == NULL) throw std::invalid_argument("Thisdata is not exsit."); else if(root->data == data)delete_node(root); else if(root->data > data)delete_data(root->lchild,data); else delete_data(root->rchild,data); } //find a specific data template BTreeNode { if(r == NULL) return r; else if(r->data == data) return r; //注意这两行是不能合并在一起的,不然可能会出现NULL->data呢 else if(r->data > data) returnfind_data(r->lchild,data); else return find_data(r->rchild,data); } //find a specific data in tree template BTreeNode { if(find_data(root,data) == NULL) throw std::invalid_argument("Thisdata is not exist."); else return find_data(root,data); } //return the maximum value template constT& SortBTree { if(root == NULL) throw std::invalid_argument("Thisis an empty Tree."); else { BTreeNode while(q->rchild != NULL) q = q->rchild; return q->data; } } //returnthe minimum value template constT& SortBTree { if(root == NULL) throw std::invalid_argument("Thisis an empty Tree."); else { BTreeNode while(q->lchild != NULL) q = q->lchild; return q->data; } } //printthe sort tree template voidSortBTree { if(p != NULL) { display(p->lchild,visit); visit(p); display(p->rchild,visit); } } #endif
① 凡本网注明稿件来源为"原创"的所有文字、图片和音视频稿件,版权均属本网所有。任何媒体、网站或个人转载、链接转贴或以其他方式复制发表时必须注明"稿件来源:我考网",违者本网将依法追究责任;
② 本网部分稿件来源于网络,任何单位或个人认为我考网发布的内容可能涉嫌侵犯其合法权益,应该及时向我考网书面反馈,并提供身份证明、权属证明及详细侵权情况证明,我考网在收到上述法律文件后,将会尽快移除被控侵权内容。