Print Left View of a Binary Tree | A binary tree node ; Recursive function pritn left view of a binary tree ; Base Case ; If this is the first node of its level ; Recur for left and right subtree ; A wrapper over leftViewUtil ( ) ; Driver program to test above function
class Node : NEW_LINE INDENT def __init__ ( self , data ) : NEW_LINE INDENT self . data = data NEW_LINE self . left = None NEW_LINE self . right = None NEW_LINE DEDENT DEDENT def leftViewUtil ( root , level , max_level ) : NEW_LINE INDENT if root is None : NEW_LINE INDENT return NEW_LINE DEDENT if ( max_level [ 0 ] < level ) : NEW_LINE INDENT print " % ▁ d TABSYMBOL " % ( root . data ) , NEW_LINE max_level [ 0 ] = level NEW_LINE DEDENT leftViewUtil ( root . left , level + 1 , max_level ) NEW_LINE leftViewUtil ( root . right , level + 1 , max_level ) NEW_LINE DEDENT def leftView ( root ) : NEW_LINE INDENT max_level = [ 0 ] NEW_LINE leftViewUtil ( root , 1 , max_level ) NEW_LINE DEDENT root = Node ( 12 ) NEW_LINE root . left = Node ( 10 ) NEW_LINE root . right = Node ( 20 ) NEW_LINE root . right . left = Node ( 25 ) NEW_LINE root . right . right = Node ( 40 ) NEW_LINE leftView ( root ) NEW_LINE