Print left view of a binary tree

Print left view of a binary tree

Here given code implementation process.

/*
  C Program 
  Left View of Binary Tree Recursion
*/
#include<stdio.h>
#include<stdlib.h>
//structure of Binary Tree node
struct Node{
  int data;
  struct Node*left,*right;
};


//Create a binary tree nodes and node fields (data,pointer) 
//And returning the reference of newly nodes
struct Node* insert(int data){
  //create dynamic memory to new binary tree node
  struct Node*new_node=(struct Node*)malloc(sizeof(struct Node));
  if(new_node!=NULL){
    //set data and pointer values
    new_node->data=data;
    new_node->left=NULL; //Initially node left-pointer is NULL
    new_node->right=NULL;//Initially node right-pointer is NULL
  }else{
    printf("Memory Overflow\n");
    exit(0); //Terminate program execution
  }
  //return reference
  return new_node;
  
}

//Display Left View of given binary tree
void left_view(struct Node*node,int up,int *back){

  if(node==NULL){
    return;
  }else if(*back<up){
    printf("%d  ",node->data );
    *back=(*back)+1;
  }
  //Recursive call
  left_view(node->left,up+1,back);
  left_view(node->right,up+1,back);

}
int main(){

  struct Node*root=NULL;
  int level=-1;
  /*  Make A Binary Tree
  -----------------------
             1
           /   \
          2     3
         /     / \
        4     5   6
       /      \    
      7        8    
              /
             9 
  */

  //Insertion of binary tree nodes
  root                    =insert(1);
  root->left              =insert(2);
  root->right             =insert(3);
  root->right->right      =insert(6);
  root->right->left       =insert(5);
  root->left->left        =insert(4);
  root->left->left->left  =insert(7);
  root->right->left->right =insert(8);
  root->right->left->right->left =insert(9);

  //Display Left view of tree
  left_view(root,0,&level);
  return 0;
}

Output

1  2  4  7  9
/*
   C++ Program 
   Left View of Binary Tree Using Recursion
*/
#include<iostream>
using namespace std;

//Structure of Binary Tree node
class Node{
public:
  int data;
  Node*left,*right;
  //make a tree node
  Node(int data){
    //assign field values
    this->data=data;
    left=right=NULL;
  }
};


class BinaryTree{
public:
  Node*root;
  BinaryTree();
  void left_view(Node*,int ,int*);

};

//set initial tree root to NULL
BinaryTree:: BinaryTree(){
  root=NULL;
}

//Display Left View of given binary tree
void  BinaryTree:: left_view(Node*node,int up,int *back){
  if(node==NULL){
    return;
  }else if(*back<up){
    cout<<"  "<<node->data;
    *back=(*back)+1;
  }
  //Recursive call
  left_view(node->left,up+1,back);
  left_view(node->right,up+1,back);
}
int main(){

  BinaryTree obj;
  int level=-1;
  /*  Make A Binary Tree
  -----------------------
             1
           /   \
          2     3
         /     / \
        4     5   6
       /       \    
      7         8
               /
              9     
  */

  //insert node of binary tree 
  obj.root                    =new Node(1);
  obj.root->left              =new Node(2);
  obj.root->right             =new Node(3);
  obj.root->right->right      =new Node(6);
  obj.root->right->left       =new Node(5);
  obj.root->left->left        =new Node(4);
  obj.root->left->left->left  =new Node(7);
  obj.root->right->left->right =new Node(8);
  obj.root->right->left->right->left =new Node(9);
  //Display Tree elements
  obj.left_view(obj.root,0,&level);
  return 0;
}

Output

/* 
   Java Program 
+  Left View of Binary Tree Using Recursion
 */


//Structure of Binary Tree node
class Node{
  public int data;
  public  Node left, right;
    //make a tree node
  public Node(int data){
        //assign field values
    this.data=data;
    left=right=null;
  }
}

class BinaryTree{
  public Node root;
  int back;
    //set initial tree root to null
  public BinaryTree(){
    root=null;
    back=-1;
  }

    //Display Left View of given binary tree
  public void leftView(Node node,int up){

    if(node==null){
      return;
    }else if(back<up){
      System.out.printf("%d  ",node.data );
      back=(back)+1;
    }
    //Recursive call
    leftView(node.left,up+1);
    leftView(node.right,up+1);

  }
  public static void main(String[] arges){
    BinaryTree obj=new BinaryTree();
      /*  Make A Binary Tree
      -----------------------
               1
             /   \
            2     3
           /     / \
          4     5   6
         /       \    
        7         8
                 /
                9       
      */

      //insert node of binary tree 
    obj.root                  =new Node(1);
    obj.root.left             =new Node(2);
    obj.root.right            =new Node(3);
    obj.root.right.right      =new Node(6);
    obj.root.right.left       =new Node(5);
    obj.root.left.left        =new Node(4);
    obj.root.left.left.left   =new Node(7);
    obj.root.right.left.right =new Node(8);
    obj.root.right.left.right.left =new Node(9);
      //Display Tree Left View Elements
        obj.leftView(obj.root,0);

      }
  }

Output

1  2  4  7  9 
#Python Program 
#Left View of Binary Tree Using Recursion

      
class Node:
    def __init__(self,data):
      #Assign node value
      self.data=data
      self.left,self.right=None,None


class BinaryTree:

    def __init__(self):
      #set initial tree pointer to null
      self.root=None
      self.back=-1


    #Display Left View of given binary tree
    def leftView(self,node,up):
        if(node==None):
          return
        elif(up>self.back):
          print(node.data,end="  ")
          self.back=self.back+1
        self.leftView(node.left,up+1)
        self.leftView(node.right,up+1)

def main():
    #Make object of Binary Tree
    obj=BinaryTree()
  #   Make A Binary Tree
  #-----------------------
  #         1
  #       /   \
  #      2     3
  #     /     / \
  #    4     5   6
  #   /       \   
  #  7         8
  #           /
  #          9   
  #
  #insertion of binary tree nodes
    obj.root = Node(1)
    obj.root.left = Node(2)
    obj.root.right = Node(3)
    obj.root.right.right = Node(6)
    obj.root.right.left = Node(5)
    obj.root.left.left= Node(4)
    obj.root.left.left.left= Node(7)
    obj.root.right.left.right= Node(8)
    obj.root.right.left.right.left= Node(9)
    #Display Tree Left view elements
    obj.leftView(obj.root,0)

  

if __name__=="__main__":
  main()

Output

1  2  4  7  9
/* 
   C# Program 
+  Left View of Binary Tree Using Recursion
 */
using System;

//Structure of Binary Tree node
class Node{
  public int data;
  public  Node left, right;
  //make a tree node
  public Node(int data){
    //assign field values
    this.data=data;
    left=right=null;
  }
}


class BinaryTree{
  public Node root;

  //set initial tree root to null
  public BinaryTree(){
    root=null;
  
  }

  //display LeftView of BST
  public void leftView(Node node,int up,ref int back){
    if(node==null){
      return;
    }else if(back<up){
      Console.Write("  {0}",node.data );
      back=(back)+1;
    }
    //Recursive call
    leftView(node.left,up+1,ref back);
    leftView(node.right,up+1,ref back);
  }
  public static void Main(){
    BinaryTree obj=new BinaryTree();
    int level = -1;
    /*  Make A Binary Tree
      -----------------------
               1
             /   \
            2     3
           /     / \
          4     5   6
         /       \    
        7         8
               /
              9 
      */

    //insert node of binary tree 
    obj.root                  =new Node(1);
    obj.root.left             =new Node(2);
    obj.root.right            =new Node(3);
    obj.root.right.right      =new Node(6);
    obj.root.right.left       =new Node(5);
    obj.root.left.left        =new Node(4);
    obj.root.left.left.left   =new Node(7);
    obj.root.right.left.right =new Node(8);
    obj.root.right.left.right.left =new Node(9);
    //Display Tree elements
    obj.leftView(obj.root,0,ref level);

  }
}

Output

 1  2  4  7  9
<?php
class Node {
  public $data;
  public $left;
  public $right;

  function __construct($data) {
    $this->data = $data;
    $this->left = $this->right = null;
  }
}
class BinaryTree {
  public $root;
  public $back;

  function __construct() {
    $this->root = null;
    $this->back = -1;
  }
  public  function leftView($node, $up) {
    if ($node == null) {
      return;
    } 
    else if ($this->back < $up) {
      printf("%d  ", $node->data);
      $this->back = ($this->back) + 1;
    }
    $this->leftView($node->left, $up + 1);
    $this->leftView($node->right, $up + 1);
  }

}

function main() {
  $obj = new BinaryTree();
  /*  Create Binary Tree
  -----------------------
           1
         /   \
        2     3
       /     / \
      4     5   6
     /       \    
    7         8
             /
            9       
  */
  $obj->root = new Node(1);
  $obj->root->left = new Node(2);
  $obj->root->right = new Node(3);
  $obj->root->right->right = new Node(6);
  $obj->root->right->left = new Node(5);
  $obj->root->left->left = new Node(4);
  $obj->root->left->left->left = new Node(7);
  $obj->root->right->left->right = new Node(8);
  $obj->root->right->left->right->left = new Node(9);
  $obj->leftView($obj->root, 0);
}
main();?>

Output

 1  2  4  7  9

We can also use Queue to solve this problem.

/*
  C Program 
  Left View of Binary Tree Using Queue

*/
#include<stdio.h>
#include<stdlib.h>
//structure of Binary Tree node
struct Node{
  int data;
  struct Node*left,*right;
};

struct Queue{
  int level;
  struct Node*element;
  struct Queue*next;
};

//Create a binary tree nodes and node fields (data,pointer) 
//And returning the reference of newly nodes
struct Node* insert(int data){
  //create dynamic memory to new binary tree node
  struct Node*new_node=(struct Node*)malloc(sizeof(struct Node));
  if(new_node!=NULL){
    //set data and pointer values
    new_node->data=data;
    new_node->left=NULL; //Initially node left-pointer is NULL
    new_node->right=NULL;//Initially node right-pointer is NULL
  }else{
    printf("Memory Overflow\n");
    exit(0); //Terminate program execution
  }
  //return reference
  return new_node;
  
}
//Create a Queue element and return this reference
struct Queue* enqueue(struct Node*tree_node){
  
  struct Queue*Queue_node=(struct Queue*)malloc(sizeof(struct Queue));
  if(Queue_node!=NULL){
      //set pointer values
      Queue_node->element=tree_node;
      Queue_node->next=NULL;
      
    }else{
    printf("Memory Overflow\n");
    exit(0); //Terminate program execution
  }
  return Queue_node;
}
//Remove Queue elements
void dequeue(struct Queue**front){
  if(*front!=NULL){
    struct Queue*remove=*front;
    *front=remove->next;
    remove->element=NULL;
    remove->next=NULL;
    free(remove);
    remove=NULL;
  }
}
//Display Left View of given binary tree
void left_view(struct Node*node){

  if(node !=NULL){
    //make Queue pointers
    struct Queue*front=NULL,
                *tail=NULL;

    //get first node of tree
    front=enqueue(node);
    front->level=0;
    tail=front;
    int check_level=-1;

    struct Node*temp=node;
    while(front!=NULL){
      temp=front->element;
      if(temp->left!=NULL){
        //add new left child node
        tail->next=enqueue(temp->left);
        tail->next->level=front->level+1;
        tail=tail->next;

      }if(temp->right!=NULL){
        //add new right child node
        tail->next=enqueue(temp->right);
        tail->next->level=front->level+1;
        tail=tail->next;
      }
      if(front->level!=check_level){
        //when new level node are coming
        check_level=front->level;
        printf("%d  ",front->element->data);
      }
  
      dequeue(&front); //remove element of queue
    }
    tail=NULL;
  }else{
    printf("Empty Linked List\n");
  }
}
int main(){

  struct Node*root=NULL;
  /*  Make A Binary Tree
  -----------------------
             1
           /   \
          2     3
         /     / \
        4     5   6
       /      \    
      7        8    
              /
             9 
  */

  //Insertion of binary tree nodes
  root                    =insert(1);
  root->left              =insert(2);
  root->right             =insert(3);
  root->right->right      =insert(6);
  root->right->left       =insert(5);
  root->left->left        =insert(4);
  root->left->left->left  =insert(7);

  root->right->left->right =insert(8);

  root->right->left->right->left =insert(9);
  //Display Left view of tree
  left_view(root);
  return 0;
}

Output

1  2  4  7  9
/*
   C++ Program 
   Left View of Binary Tree Using Queue
*/
#include<iostream>
using namespace std;

//Structure of Binary Tree node
class Node{
public:
  int data;
  Node*left,*right;
  //make a tree node
  Node(int data){
    //assign field values
    this->data=data;
    left=right=NULL;
  }
};
class Queue
{

public:
  Node*element;
  Queue*next;
  int level;
  Queue(Node*element){
    this->element=element;
    this->next=NULL;
  }
};

class BinaryTree{
public:
  Node*root;
  BinaryTree();
  void left_view(Node*);
  Queue * enqueue(Node*);
  void dequeue(Queue**);
};

//set initial tree root to NULL
BinaryTree:: BinaryTree(){
  root=NULL;

}
//Add queue element
Queue * BinaryTree:: enqueue(Node*element){

  Queue *newNode=new Queue(element);
  if(newNode==NULL){
    cout<<"Memory overflow"<<endl;
  }
  newNode->element=element;
  newNode->next=NULL;

  return newNode;
}
//Remove a queue element
void  BinaryTree:: dequeue(Queue**head){
  if(*head!=NULL){
    Queue*temp=*head;
    *head=temp->next;
    temp->element=NULL;
    temp->next=NULL;
    delete temp;
    temp=NULL;
  }

}

////Display Left View of given binary tree
void  BinaryTree:: left_view(Node*node){

  if(node !=NULL){
    //make Queue pointers
    Queue*front=NULL,
          *tail=NULL;

    //get first node of tree
    front=enqueue(node);
    front->level=0;
    tail=front;
    int check_level=-1;

    Node*temp=node;
    while(front!=NULL){
      temp=front->element;
      if(temp->left!=NULL){
        //add new left child node
        tail->next=enqueue(temp->left);
        tail->next->level=front->level+1;
        tail=tail->next;

      }if(temp->right!=NULL){
        //add new right child node
        tail->next=enqueue(temp->right);
        tail->next->level=front->level+1;
        tail=tail->next;
      }
      if(front->level!=check_level){
        //when new level node are coming
        check_level=front->level;
       //display elements
      cout<<" "<<temp->data;
      }
      
      dequeue(&front); //remove element of queue
    }
    tail=NULL;
  }else{
    cout<<"Empty Linked List"<<endl;
  }
}
int main(){

  BinaryTree obj;
  /*  Make A Binary Tree
  -----------------------
             1
           /   \
          2     3
         /     / \
        4     5   6
       /       \    
      7         8
               /
              9     
  */

  //insert node of binary tree 
  obj.root                    =new Node(1);
  obj.root->left              =new Node(2);
  obj.root->right             =new Node(3);
  obj.root->right->right      =new Node(6);
  obj.root->right->left       =new Node(5);
  obj.root->left->left        =new Node(4);
  obj.root->left->left->left  =new Node(7);

  obj.root->right->left->right =new Node(8);
  obj.root->right->left->right->left =new Node(9);
  //Display Tree elements
  obj.left_view(obj.root);
  return 0;
}

Output

1 2 4 7 9
/* 
   Java Program 
+  Left View of Binary Tree Using Queue
 */


//Structure of Binary Tree node
class Node{
  public int data;
  public  Node left, right;
    //make a tree node
  public Node(int data){
        //assign field values
    this.data=data;
    left=right=null;
  }
}
class Queue
{

  public Node element;
  public Queue next;
  public int level;
  public  Queue(Node element){
    this.element=element;
    this.next=null;
  }

}

class BinaryTree{
  public Node root;
  Queue head, tail;
  //set initial tree root to null
  public BinaryTree(){
    root=null;
    head=null;
    tail=null;
  }
  //Remove a queue element
  public Queue enqueue(Node element){

    Queue  newNode=new Queue(element);

    if(head==null) head=newNode;
    if(tail==null) tail=newNode;
    else{
      tail.next=newNode;
      tail=newNode;
    }
    return newNode;

  }

  //Remove a queue element
  public void dequeue(){
    if(head!=null){
      Queue temp=head;
      if(head==tail){
        tail=null;
      }
      head=head.next;
      temp.element=null;
      temp.next=null;
      temp=null;
    }

  }
  //Display Left View of given binary tree
  public void leftView(Node node){

    if(node!=null){
      if(node !=null){
       
        Node temp=null;
        Queue hold=null;
        //get first node of tree
        hold=enqueue(node);
        hold.level=0;
        int checkLevel=-1;
        while(head!=null){
          temp=head.element;
          if(temp.left!=null){
            //add new left child node
            hold=enqueue(temp.left);
            hold.level=head.level+1;

          }if(temp.right!=null){
            //add new right child node
            hold=enqueue(temp.right);
            hold.level=head.level+1;
          }

           
          if(checkLevel!=head.level){
            //display elements
            System.out.print("  "+temp.data);
            checkLevel=head.level;
          }
              dequeue(); //remove element of queue
        }

      }else{
        System.out.println("Empty Binary Tree List\n");
      }

    }
  }
  public static void main(String[] arges){
    BinaryTree obj=new BinaryTree();
    /*  Make A Binary Tree
    -----------------------
             1
           /   \
          2     3
         /     / \
        4     5   6
       /       \    
      7         8
               /
              9       
    */

    //insert node of binary tree 
    obj.root                  =new Node(1);
    obj.root.left             =new Node(2);
    obj.root.right            =new Node(3);
    obj.root.right.right      =new Node(6);
    obj.root.right.left       =new Node(5);
    obj.root.left.left        =new Node(4);
    obj.root.left.left.left   =new Node(7);
    obj.root.right.left.right =new Node(8);
    obj.root.right.left.right.left =new Node(9);
      //Display Tree Left View Elements
      obj.leftView(obj.root);

    }
}

Output

  1  2  4  7  9
#Python Program 
#Left View of Binary Tree Using Queue
class Queue:
    def __init__(self,element):
      #Assign node value
      self.element=element
      self.next=None
      self.level=0
      
class Node:
    def __init__(self,data):
      #Assign node value
      self.data=data
      self.left,self.right=None,None


class BinaryTree:

    def __init__(self):
      #set initial tree pointer to null
      self.root=None
      self.head=None
      self.tail=None
    #add Queue elements
    def enqueue(self,node):
        newNode=Queue(node)
        if(self.head==None):
          self.head=newNode
        if(self.tail==None):
          self.tail=newNode
        else:
          newNode.level=self.head.level+1  
          self.tail.next=newNode
          self.tail=newNode
        

    #Remove Queue Elements    
    def dequeue(self):
        if(self.head!=None):
          temp=self.head
          if(self.head==self.tail):
            self.tail=None

            
          self.head=self.head.next
          temp.element=None
          temp.next=None
          temp=None

    #Display Left View of given binary tree
    def leftView(self,node):
        if(node!=None):
          self.enqueue(node)
          checkLevel=-1;
          while(self.head!=None):
            current=self.head.element
            if(current.left!=None):
              self.enqueue(current.left)
            if(current.right!=None):
              self.enqueue(current.right)
            if(checkLevel!=self.head.level):
              print(current.data,end="  ")
              checkLevel=self.head.level
            self.dequeue()


def main():
    #Make object of Binary Tree
    obj=BinaryTree()
  #   Make A Binary Tree
  #-----------------------
  #         1
  #       /   \
  #      2     3
  #     /     / \
  #    4     5   6
  #   /       \   
  #  7         8
  #           /
  #          9   
  #
  #insertion of binary tree nodes
    obj.root = Node(1)
    obj.root.left = Node(2)
    obj.root.right = Node(3)
    obj.root.right.right = Node(6)
    obj.root.right.left = Node(5)
    obj.root.left.left= Node(4)
    obj.root.left.left.left= Node(7)
    obj.root.right.left.right= Node(8)
    obj.root.right.left.right.left= Node(9)
    #Display Tree Left view elements
    obj.leftView(obj.root)

  

if __name__=="__main__":
  main()

Output

1  2  4  7  9
/* 
   C# Program 
+  Left View of Binary Tree Using Queue
 */
using System;

//Structure of Binary Tree node
class Node{
  public int data;
  public  Node left, right;
  //make a tree node
  public Node(int data){
    //assign field values
    this.data=data;
    left=right=null;
  }
}
class Queue
{

  public Node element;
  public Queue next;
  public int level;
  public  Queue(Node element){
    this.element=element;
    this.next=null;
  }

}

class BinaryTree{
  public Node root;
  Queue head, tail;
  //set initial tree root to null
  public BinaryTree(){
    root=null;
    head=null;
    tail=null;
  }
  public Queue enqueue(Node element){

    Queue  newNode=new Queue(element);

    if(head==null) head=newNode;
    if(tail==null) tail=newNode;
    else{
      tail.next=newNode;
      tail=newNode;
    }
    return newNode;

  }

  //Remove a queue element
  public void dequeue(){
    if(head!=null){
      Queue temp=head;
      if(head==tail){
        tail=null;
      }
      head=head.next;
      temp.element=null;
      temp.next=null;
      temp=null;
    }

  }
  //display LeftView of BST
  public void leftView(Node node){

    if(node!=null){
      if(node !=null){

        Node temp=null;
        Queue hold=null;
        //get first node of tree
        hold=enqueue(node);
        hold.level=0;
        int checkLevel = -1;
        while(head!=null){
          temp=head.element;
          if(temp.left!=null){
            //add new left child node
            hold=enqueue(temp.left);
            hold.level=head.level+1;

          }if(temp.right!=null){
            //add new right child node
            hold=enqueue(temp.right);
            hold.level=head.level+1;
          }


          if(checkLevel != head.level){
            //display elements
            Console.Write("  {0}",temp.data);
            checkLevel = head.level;
          }
          dequeue(); //remove element of queue
        }

      }else{
        Console.Write("Empty Binary Tree List\n");
      }

    }
  }
  public static void Main(){
    BinaryTree obj=new BinaryTree();
    /*  Make A Binary Tree
    -----------------------
             1
           /   \
          2     3
         /     / \
        4     5   6
       /       \    
      7         8
               /
              9    
    */

    //insert node of binary tree 
    obj.root                  =new Node(1);
    obj.root.left             =new Node(2);
    obj.root.right            =new Node(3);
    obj.root.right.right      =new Node(6);
    obj.root.right.left       =new Node(5);
    obj.root.left.left        =new Node(4);
    obj.root.left.left.left   =new Node(7);
    obj.root.right.left.right =new Node(8);
    obj.root.right.left.right.left =new Node(9);
    //Display Tree elements
    obj.leftView(obj.root);

  }
}

Output

  1  2  4  7  9
<?php
class Node {
  public $data;
  public $left;
  public $right;

  function __construct($data) {
    $this->data = $data;
    $this->left = $this->right = null;
  }
}
class Queue {
  public $element;
  public $next;
  public $level;

  function __construct($element) {
    $this->element = $element;
    $this->next = null;
  }
}
class BinaryTree {
  public $root;
  public $head;
  public $tail;

  function __construct() {
    $this->root = null;
    $this->head = null;
    $this->tail = null;
  }
  public  function enqueue($element) {
    $newNode = new Queue($element);
    if ($this->head == null) $this->head = $newNode;
    if ($this->tail == null) $this->tail = $newNode;
    else {
      $this->tail->next = $newNode;
      $this->tail = $newNode;
    }
    return $newNode;
  }
  public  function dequeue() {
    if ($this->head != null) {
      $temp = $this->head;
      if ($this->head == $this->tail) {
        $this->tail = null;
      }
      $this->head = $this->head->next;
      $temp->element = null;
      $temp->next = null;
      $temp = null;
    }
  }
  public  function leftView($node) {
    if ($node != null) {
      if ($node != null) {
        $temp = null;
        $hold = null;
        $hold = $this->enqueue($node);
        $hold->level = 0;
        $checkLevel = -1;
        while ($this->head != null) {
          $temp = $this->head->element;
          if ($temp->left != null) {
            $hold = $this->enqueue($temp->left);
            $hold->level = $this->head->level + 1;
          }
          if ($temp->right != null) {
            $hold = $this->enqueue($temp->right);
            $hold->level = $this->head->level + 1;
          }
          if ($checkLevel != $this->head->level) {
            echo("  ". $temp->data);
            $checkLevel = $this->head->level;
          }
          $this->dequeue();
        }
      } else {
        echo("Empty Binary Tree List\n");
      }
    }
  }

}
function main() {
  $obj = new BinaryTree();
  /* Make A Binary Tree
  -----------------------
         1
       /   \
      2     3
     /     / \
    4     5   6
   /       \    
  7         8
           /
          9       
  */


  $obj->root = new Node(1);
  $obj->root->left = new Node(2);
  $obj->root->right = new Node(3);
  $obj->root->right->right = new Node(6);
  $obj->root->right->left = new Node(5);
  $obj->root->left->left = new Node(4);
  $obj->root->left->left->left = new Node(7);
  $obj->root->right->left->right = new Node(8);
  $obj->root->right->left->right->left = new Node(9);
  $obj->leftView($obj->root);
}
main();
?>


Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment







© 2021, kalkicode.com, All rights reserved