-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathp3.cpp
More file actions
36 lines (29 loc) · 775 Bytes
/
Copy pathp3.cpp
File metadata and controls
36 lines (29 loc) · 775 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "ADTBiTree.cpp"
template<typename T>
bool DeleteValXChild(BiTree<T>& b,const T &x){
if(not b.root) return 0;
if(b.getRoot()==x){
b.clear();
return 1;
}
auto lt=BiTree<T>(b.root->lchild);
if(DeleteValXChild(lt,x)) b.root->lchild=nullptr;
auto rt=BiTree<T>(b.root->rchild);
if(DeleteValXChild(rt,x)) b.root->rchild=nullptr;
return 0;
}
int main(){
BiTree<char> b;
b.create(cin);
cout<<"b is created by in3.txt"<<endl<<endl;
auto print=[](auto e){cout<<e<<" ";};
cout<<"PreOrderTraverse(b): ";
b.preOrderTraverse(print);
cout<<endl;
DeleteValXChild(b,'6');
cout<<"delete 6"<<endl;
cout<<"PreOrderTraverse(b): ";
b.preOrderTraverse(print);
cout<<endl;
return 0;
}