Binary Search Tree in python
I have written a Binary Search Tree Implementation in Python,

And I am getting errors while I print the inorder search of it.

Please kindly let me know what is the issue in the implementation.

Kindly do correction in this implementation only.


    #!/usr/bin/python
    
    class node:
      def __init__(self, info):
        self.info = info
        self.left = None
        self.right = None
    
      def getInfo(self):
        return self.info
    
      def __str__(self):
        return str(self.info)
    
    class tree:
      def __init__(self):
        self.root = None
    
      def insert(self, n):
        if self.root == None:
          self.root = n
        else:
          self._insert(self.root, n)
    
      def _insert(self, root, n):
        if(root == None):
          return n
    
        if(n.getInfo() <= root.getInfo()):
          root.left = self._insert(root.left, n)
        else:
          root.right = self._insert(root.right, n)
    
      def traverse(self):
        self._traverse(self.root)
    
      def _traverse(self, root):
        if(root == None):
          return
        self._traverse(root.left)
        print root,
        self._traverse(root.right)
    
    
    list = [8, 3, 10, 1, 6, 14, 4, 7, 13]
    
    t = tree()
    for l in list:
      t.insert(node(l))
    
    t.traverse()


Binary Search Tree in python
===

I have written a Binary Search Tree Implementation in Python,

And I am getting errors while I print the inorder search of it.

Please kindly let me know what is the issue in the implementation.

Kindly do correction in this implementation only.


    #!/usr/bin/python
    
    class node:
      def __init__(self, info):
        self.info = info
        self.left = None
        self.right = None
    
      def getInfo(self):
        return self.info
    
      def __str__(self):
        return str(self.info)
    
    class tree:
      def __init__(self):
        self.root = None
    
      def insert(self, n):
        if self.root == None:
          self.root = n
        else:
          self._insert(self.root, n)
    
      def _insert(self, root, n):
        if(root == None):
          return n
    
        if(n.getInfo() <= root.getInfo()):
          root.left = self._insert(root.left, n)
        else:
          root.right = self._insert(root.right, n)
    
      def traverse(self):
        self._traverse(self.root)
    
      def _traverse(self, root):
        if(root == None):
          return
        self._traverse(root.left)
        print root,
        self._traverse(root.right)
    
    
    list = [8, 3, 10, 1, 6, 14, 4, 7, 13]
    
    t = tree()
    for l in list:
      t.insert(node(l))
    
    t.traverse()

