I'm trying to implement Binary Search tree in python using recursion. I got trapped in some infinite recursions happening in my program.I'm making recursive calls to the function RecursBST by passing address and the data until the top traverse down to None value of either it's left or right child.
class createnode:
def __init__(self,data):
self.root=data
self.left=None
self.right=None
class createbinarysearchtree:
def __init__(self, data = None):
self.top=None
def RecursBST(self,top,data):
if self.top is None:
self.top=createnode(data)
elif self.top.root>data:
self.top.left=self.RecursBST(self.top.left,data)
elif self.top.root<data:
self.top.right=self.RecursBST(self.top.right,data)
conv=createbinarysearchtree();
conv.RecursBST(conv.top,50)
conv.RecursBST(conv.top,40)
I ran to the below error :
self.top.left=self.RecursBST(self.top.left,data)
RuntimeError: maximum recursion depth exceeded

leftandrightare. Also, what happens when you callRecursBSTanddata == self.top.root?RecurseBSTdoesn't return anything, so the assignments toself.top.leftandself.top.rightdon't make sense.insert(),delete(), andsearch(). Your current implementation is confusing things by performing insertion-related work (creating a node) with search-related work. Also, there's a related style note that adds to this general confusion: normally classes are things or nouns (BinarySearchTreeorNode) not actions (createnodeorcreatebinarysearchtree).