I've been practicing data structures i'm able to insert a node and display , but i'm not able to understand the recursion used to display the tree
class node:
def __init__(self, data=None):
self.data = data
self.right = None
self.left = None
class Binary_search_tree:
def __init__(self):
self.root = None
self.i = 0
def insert(self, value):
if self.root == None:
self.root = node(value)
else:
self._insert(value, self.root)
def _insert(self, value, current_node):
if value > current_node.data:
if current_node.right == None:
current_node.right = node(value)
else:
self._insert(value, current_node.right)
elif current_node.data > value:
if current_node.left == None:
current_node.left = node(value)
else:
self._insert(value, current_node.left)
def display(self):
if self.root != None:
self._display(self.root)
def _display(self, current_node):
if current_node != None:
self._display(current_node.left)
print(current_node.data)
self._display(current_node.right)
I've done as many walkthroughs as i can but i end up with the None loop, about which i have no idea how it further proceeds
def _display(self, current_node):
if current_node != None:
self._display(current_node.left)
print(current_node.data)
self._display(current_node.right)