I am trying to decipher this code posted a few years back over here: How to implement a binary search tree in Python?
The part that I am confused about is this section:
class Node:
def __init__(self, val):
self.l_child = None
self.r_child = None
self.data = val
def binary_insert(root, node):
if root is None:
root = node
else:
if root.data > node.data:
if root.l_child is None:
root.l_child = node
else:
binary_insert(root.l_child, node)
else:
if root.r_child is None:
root.r_child = node
else:
binary_insert(root.r_child, node)
The class and functions are then called by doing this:
r = Node(3)
binary_insert(r, Node(7))
binary_insert(r, Node(1))
binary_insert(r, Node(5))
My question is: what happened to self.data when passed into the binary_insert function? Where did node.data and root.data come from?