Print Left View of a Binary Tree | C ++ program to print left view of Binary Tree ; A Binary Tree Node ; Utility function to create a new tree node ; function to print left view of binary tree ; number of nodes at current level ; Traverse all nodes of current level ; Print the left most element at the level ; Add left node to queue ; Add right node to queue ; Driver code ; Let 's construct the tree as  shown in example
#include <bits/stdc++.h> NEW_LINE using namespace std ; struct Node { int data ; struct Node * left , * right ; } ; Node * newNode ( int data ) { Node * temp = new Node ; temp -> data = data ; temp -> left = temp -> right = NULL ; return temp ; } void printLeftView ( Node * root ) { if ( ! root ) return ; queue < Node * > q ; q . push ( root ) ; while ( ! q . empty ( ) ) { int n = q . size ( ) ; for ( int i = 1 ; i <= n ; i ++ ) { Node * temp = q . front ( ) ; q . pop ( ) ; if ( i == 1 ) cout << temp -> data << " ▁ " ; if ( temp -> left != NULL ) q . push ( temp -> left ) ; if ( temp -> right != NULL ) q . push ( temp -> right ) ; } } } int main ( ) { Node * root = newNode ( 10 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 3 ) ; root -> left -> left = newNode ( 7 ) ; root -> left -> right = newNode ( 8 ) ; root -> right -> right = newNode ( 15 ) ; root -> right -> left = newNode ( 12 ) ; root -> right -> right -> left = newNode ( 14 ) ; printLeftView ( root ) ; }