-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathp4.cpp
More file actions
34 lines (27 loc) · 780 Bytes
/
Copy pathp4.cpp
File metadata and controls
34 lines (27 loc) · 780 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
#include "ADTBiTree.cpp"
#include<tuple>
template<typename T>
tuple<int,int,bool> _IsComplete(BiNode<T>* b){
if(not b) return {-1,-1,true};
auto [ll,lr,lb]=_IsComplete(b->lchild);
auto [rl,rr,rb]=_IsComplete(b->rchild);
if(lb and rb and lr>=rl and ll-rr<=1)
return {1+ll,1+rr,true};
return {-1,-1,false};
}
template<typename T>
bool IsComplete(BiTree<T> b){
auto [ld,rd,flag]=_IsComplete(b.root);
return flag;
}
int main(){
BiTree<char> b;
b.create(cin);
cout<<"b is created by in4.txt"<<endl<<endl;
auto print=[](auto e){cout<<e<<" ";};
cout<<"LevelOrderTraverse(b): ";
b.levelOrderTraverse([](auto e){cout<<e<<' ';});
cout<<endl;
cout<<"b is complete binary tree: "<<IsComplete(b)<<endl;
return 0;
}