Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<queue>
- using namespace std;
- class Node{
- public:
- int data;
- Node *left,*right;
- Node(int key){
- data=key;
- left=NULL;
- right=NULL;
- }
- };
- void PrintLeftView(Node *root){
- if(root==NULL)
- return ;
- queue<Node*>q;
- q.push(root);
- q.push(NULL);
- cout<<" "<<root->data;
- while(!q.empty()){
- Node *temp=q.front();
- q.pop();
- if(temp!=NULL){
- if(temp->left!=NULL)
- q.push(temp->left);
- if(temp->right!=NULL)
- q.push(temp->right);
- }
- else
- if(q.size()>0){
- q.push(NULL);
- temp=q.front();
- cout<<" "<<temp->data;
- }
- }
- }
- int main(){
- Node *root=NULL;
- Node *newnode=new Node(1);
- root=newnode;
- root->left=new Node(2);
- root->right=new Node(3);
- (root->left)->left=new Node(4);
- (root->right)->right=new Node(5);
- ((root->left)->left)->left=new Node(6);
- PrintLeftView(root);
- return 0;
- }
Add Comment
Please, Sign In to add comment