OneCompiler

PYTHON BINARY TREE OUTER LEFT ALL ELEMENT PRINTING

184

PYTHON BINARY TREE


```python
 class node:
  #for every node
  def __init__(self,data):
    self.data=data
    self.left=None
    self.right=None
  
  #for adding a data and node
  def insert(self,data):
    if self.data:
      if data<self.data:
        if self.left is None:
          self.left=node(data)
        else:
          self.left.insert(data)
      if data>self.data:
        if self.right is None:
          self.right=node(data)
        else:
          self.right.insert(data)
    else:
      self.data=data
    
    
  #for printing the tree
  def printtree(self):
    if self.left:
      self.left.printtree()
    print(self.data)
    # if self.right:
    #   self.right.printtree()
    
  
call1=node(10)
call1.insert(7)
call1.insert(14)
call1.insert(14)
call1.insert(2)
call1.insert(5)
call1.insert(8)

call1.printtree()


```