-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtree-1
68 lines (59 loc) · 1.21 KB
/
tree-1
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
void leftView(Node *root)
{
std::queue<Node*>q;
q.push(root);
q.push(NULL);
while(!q.empty()){
Node* tmp = q.front();
if(tmp!=NULL)
std::cout<<tmp->data<<" ";
while(q.front()!=NULL){
if(q.front()==NULL)
q.pop();
if(tmp->left)
q.push(tmp->left);
if(tmp->right)
q.push(tmp->right);
q.pop();
tmp = q.front();
}
q.pop();
if(!q.empty())
q.push(NULL);
}
}
void leftViewBFSUtil(Node* root,int n){
leftViewBFS(root,0,1);
}
void leftViewBFS(Node *root,int &r,int h)
{
if(root==NULL)
return;
if(r<h){
std::cout<<root->data<<" ";
r=h;
}
leftViewBFS(root->left,r,h+1);
leftViewBFS(root->right,r,h+1);
}
bool isBST(Node* root) {
if(root==NULL)
return true;
static Node* prev=NULL;
isBST(root->left);
if(prev==NULL)
prev=root;
else{
// std::cout<<prev->data<<" "<<root->data<<"\n";
if(prev->data>root->data)
return false;
prev=root;
}
isBST(root->right);
return true;
}
int main()
{
return 0;
}