#includeusing namespace std;
//二叉搜尋樹左兒子的值比當前節點小,右兒子的數值比當前節點大
struct node
;//建立樹
node *insert(node *p,int x)
else
return p;
}//查詢
bool find(node* p,int x)
else return find(p->rchd,x);
}//刪除數值
node *remove(node* p,int x)
else if(p->lchd->rchd==null)
else
return p;
}void print(node* p)//中序遍歷
void releasetree(node* p)//釋放整棵樹
int main()
; node* root=null;
for(int i=0;i<12;i++)
cout<<"the tree before delele:";
print(root);
cout
cout<<"the number "<<21<<"does exist!!"
cout<<"the tree after delele:";
print(root);
cout
cout<<"the number "<<21<<"does exist!!"
releasetree(root);//釋放節點
return 0;
}
二叉搜尋樹 二叉搜尋樹
題目 二叉搜尋樹 time limit 2000 1000 ms j a others memory limit 32768 32768 k j a others total submission s 6945 accepted submission s 3077 problem descripti...
二叉搜尋樹的實現
binarysearchtree.h inte ce for the binarysearchtree class.include binarytreenode.h include binarytree1.h if defined afx binarysearchtree h 1cd2ff9d 73...
二叉搜尋樹的實現
二叉搜尋樹的刪除 1 沒有左孩子,直接把右孩子替代刪除結點 2 有左孩子但左孩子沒有右孩子,則把左孩子替代刪除結點 3 其它,把左孩子的最大的結點替代刪除結點 時間複雜度o logn include include struct node node ins node p,int val else e...