Print Left View of a Binary Tree | Class containing left and right child of current node and key value ; Class to print the left view ; Recursive function to print left view ; Base Case ; If this is the first node of its level ; Recur for left and right subtrees ; A wrapper over leftViewUtil ( ) ; Driver code
class Node { constructor ( item ) { this . data = item ; this . left = null ; this . right = null ; } } var root ; var max_level = 0 ; function leftViewUtil ( node , level ) { if ( node == null ) { return ; } if ( max_level < level ) { document . write ( " " + node . data ) ; max_level = level ; } leftViewUtil ( node . left , level + 1 ) ; leftViewUtil ( node . right , level + 1 ) ; } function leftView ( ) { leftViewUtil ( root , 1 ) ; } root = new Node ( 12 ) ; root . left = new Node ( 10 ) ; root . right = new Node ( 30 ) ; root . right . left = new Node ( 25 ) ; root . right . right = new Node ( 40 ) ; leftView ( ) ;