I just started learning data structures, I'm trying to learn binary tree implementation using python and found an article at a website. But I don't understand code on line 12 and 18, where it says self.left.insert(data) and self.right.insert(data). Can somebody explain me what is going on there? Thank you!
class Node:
def __init__(self, data):
self.left = None
self.right = None
self.data = data
def insert(self, data):
"""Compare node to parent node, decide to add new node as a left or a right node."""
if self.data: # if data is not none type
if data < self.data: # if new node is smaller than the parent node
if self.left is None: # if there is no left node
self.left = Node(data) # add as a left node
else: # ???
self.left.insert(data) # ???
elif data > self.data: # if new node is greater than the parent node
if self.right is None: # and if right node is empty
self.right = Node(data) # add as a right node
else: # ????
self.right.insert(data)
else: # no root node, create it
self.data = data