class Node:
def __init__(self, data):
self.data = data
self.left_child = None
self.right_child = None
class Tree:
def __init__(self):
self.root_node = None
def insert(self, data):
# 1. create the Node object with the data
node = Node(data)
# 2. if root is None, make this new node the root
if self.root_node == None:
self.root_node = node
else:
# 3. if root exists, then create a current pointer initialized to root, and a parent pointer (None initially)
current = self.root_node
parent = None
# 4. go into "while True:" loop and in loop make parent the current
while True:
parent = current
# 5. in loop compare the new node data to current node data and either go left side
# or right side of tree (and....
if node.data <= current.data:
current = current.left_child
?????????????????????????????????????????????????????????????????????
?????????????????????????????????????????????????????????????????
?????????????????????????????????????????????????????????????????
else:
current = current.right_child
?????????????????????????????????????????????????????????????????????
?????????????????????????????????????????????????????????????????
?????????????????????????????????????????????????????????????????
# 5. in loop compare the new node data to current node data and either go left side
# or right side of tree and ...
if node.data <= current.data:
current = current.left_child
#...and if you hit current of None, use the parent pointer to insert new node and
# short circuit loop, other wise the loop will continue down the tree
if current is None:
parent.left_child = node
return
else:
current = current.right_child
#...and if you hit current of None, use the parent pointer to insert new node and
# short circuit loop, other wise the loop will continue down the tree
if current is None:
parent.right_child = node
return
class Node:
def __init__(self, data):
self.data = data
self.left_child = None
self.right_child = None
class Tree:
def __init__(self):
self.root_node = None
def insert(self, data):
# 1. create the Node object with the data
node = Node(data)
# 2. if root is None, make this new node the root
if self.root_node == None:
self.root_node = node
else:
# 3. if root exists, then create a current pointer initialized to root, and a parent pointer (None initially)
current = self.root_node
parent = None
# 4. go into "while True:" loop and in loop make parent the current
while True:
parent = current
# 5. in loop compare the new node data to current node data and either go left side
# or right side of tree (and....
if node.data <= current.data:
current = current.left_child
?????????????????????????????????????????????????????????????????????
?????????????????????????????????????????????????????????????????
?????????????????????????????????????????????????????????????????
else:
current = current.right_child
?????????????????????????????????????????????????????????????????????
?????????????????????????????????????????????????????????????????
?????????????????????????????????????????????????????????????????
class Node:
def __init__(self, data):
self.data = data
self.left_child = None
self.right_child = None
class Tree:
def __init__(self):
self.root_node = None
def insert(self, data):
# 1. create the Node object with the data
node = Node(data)
# 2. if root is None, make this new node the root
if self.root_node == None:
self.root_node = node
else:
# 3. if root exists, then create a current pointer initialized to root, and a parent pointer (None initially)
current = self.root_node
parent = None
# 4. go into "while True:" loop and in loop make parent the current
while True:
parent = current
# 5. in loop compare the new node data to current node data and either go left side
# or right side of tree (and....
if node.data <= current.data:
current = current.left_child
?????????????????????????????????????????????????????????????????????
?????????????????????????????????????????????????????????????????
?????????????????????????????????????????????????????????????????
else:
current = current.right_child
?????????????????????????????????????????????????????????????????????
?????????????????????????????????????????????????????????????????
?????????????????????????????????????????????????????????????????
# 5. in loop compare the new node data to current node data and either go left side
# or right side of tree and ...
if node.data <= current.data:
current = current.left_child
#...and if you hit current of None, use the parent pointer to insert new node and
# short circuit loop, other wise the loop will continue down the tree
if current is None:
parent.left_child = node
return
else:
current = current.right_child
#...and if you hit current of None, use the parent pointer to insert new node and
# short circuit loop, other wise the loop will continue down the tree
if current is None:
parent.right_child = node
return
status | not learned | measured difficulty | 37% [default] | last interval [days] | |||
---|---|---|---|---|---|---|---|
repetition number in this series | 0 | memorised on | scheduled repetition | ||||
scheduled repetition interval | last repetition or drill |