-
Notifications
You must be signed in to change notification settings - Fork 3
/
Day-39
35 lines (29 loc) · 1.02 KB
/
Day-39
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
bool isHeap(struct Node* tree) {
// code here
if(!tree) return true;
queue<Node *> q;
q.push(tree);
while(!q.empty()){
int size=q.size();
vector<int> st;
st.push_back(1);
while(size--){
Node *t=q.front();
q.pop();
if(t->left){
if(st.back()==0) return false;
if(t->data<t->left->data) return false;
q.push(t->left);
st.push_back(t->left->data);
}
else st.push_back(0);
if(t->right){
if(st.back()==0) return false;
if(t->data<t->right->data) return false;
q.push(t->right);
st.push_back(t->right->data);}
else st.push_back(0);
}
}
return true;
}