-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleftviewoftree.cpp
More file actions
65 lines (53 loc) · 919 Bytes
/
Copy pathleftviewoftree.cpp
File metadata and controls
65 lines (53 loc) · 919 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
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
#include<iostream>
#include<queue>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
struct Node{
int data;
Node *left;
Node *right;
};
struct Node* newNode(int n){
Node *temp=new Node();
temp->data=n;
temp->left=NULL;
temp->right=NULL;
return temp;
}
int turn=1;
void leftview(Node *root){
if(root==NULL){
return ;
}
queue<Node *>q;
q.push(root);
while(!q.empty()){
Node *t1=q.front();
q.pop();
if(turn==0){
turn =1;
cout<<t1->data<<endl;
cout<<"turn "<< turn <<endl;
}
if(turn ==1){
turn =0;
cout<<"turn "<< turn <<endl;
}
if(t1->left!=NULL){
q.push(t1->left);
}
if(t1->right!=NULL){
q.push(t1->right);
}
}
}
int main(){
struct Node *root = newNode(12);
root->left = newNode(10);
root->right = newNode(30);
root->right->left = newNode(25);
root->right->right = newNode(40);
leftview(root);
//leftview(root);
}