-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbt_complete.cpp
52 lines (42 loc) · 857 Bytes
/
bt_complete.cpp
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Check whether a BT is complete tree or not.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef struct node st;
struct node
{
ll data,vc;;
st *left,*right;
};
st *newNode(ll data)
{
st *temp = new node();
temp->data=data;
temp->vc=0;
temp->left=temp->right=NULL;
return temp;
}
bool complete(st *root)
{
if(root==NULL)
return true;
if(root->left==NULL and root->right== NULL)
return true;
if((root->left==NULL and root->right!=NULL) or (root->left!=NULL and root->right==NULL))
return false;
return (complete(root->left) and complete(root->right));
}
int main()
{
struct node* root = NULL;
root=newNode(1);
root->left=newNode(2);
root->right=newNode(3);
root->left->left=newNode(4);
//cout<<vertex_cover(root);
if(complete(root))
cout<<"yes";
else
cout<<"no";
return 0;
}