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 |
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 |
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. ???????????????????????????????????????????????????????
# ??????????????????????????????????????????????????????????
# 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. start a loop to keep going down until you find place to insert new Node, loop will short circuit when place found
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 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 node.data < current.data:
current = current.left_child
if current is None:
parent.left_child = node
return
else:
current = current.right_child
if current is None:
parent.right_child = node
return
def insert(self, data):
# 1. create the Node object with the data
node = Node(data)
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 |
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. ??????????????????????????????????????????????
???????????????????????????????????????????????????
???????????????????????????????????????????????????
else:
# 3. create a current pointer initialized to root, and a parent pointer (None initially)
current = self.root_node
parent = None
# 4. start a loop to keep going down until you find place to insert new Node, loop will short circuit when place found
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 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 node.data <= current.data:
current = current.left_child
if current is None:
parent.left_child = node
return
else:
current = current.right_child
if current is None:
parent.right_child = node
return
# 2. if root is None, make this new node the root
if self.root_node == None:
self.root_node = node
else:
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 |
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. ????????????????????????????????????????????????????????????
?????????????????????????????????????????????????????????????????
?????????????????????????????????????????????????????????????????
# 4. start a loop to keep going down until you find place to insert new Node, loop will short circuit when place found
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 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 node.data <= current.data:
current = current.left_child
if current is None:
parent.left_child = node
return
else:
current = current.right_child
if current is None:
parent.right_child = node
return
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
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 |
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. ???????????????????????????????????????????????????????????
????????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????????
# 5. in loop compare the new node data to current node data and either go left side
# or right side of tree (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 node.data <= current.data:
current = current.left_child
if current is None:
parent.left_child = node
return
else:
current = current.right_child
if current is None:
parent.right_child = node
return
# 4. go into "while True:" loop and in loop make parent the current
while True:
parent = current
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 |
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. ?????????????????????????????????????????????????????????????????????
??????????????????????????????????????????????????????????????????????????
??????????????????????????????????????????????????????????????????????
if current is None:
parent.left_child = node
return
??????????????????????????????????????????????????????????????????????????
??????????????????????????????????????????????????????????????????????
if current is None:
parent.right_child = node
return
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.....
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
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 |
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 |
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 |
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 |
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 |
get the pointer to node to delete and its parent (using helper method: get_node_with_parent(self, data), which returns (parent, node) ):
Here is the helper function implementation (as a bonus):
def __get_node_with_parent(self, data):
parent = None
current = self.root_node
while current:
if data == current.data:
return (parent, current)
parent = current
if data < current.data:
current = current.left_child
else:
current = current.right_child
return (None, None)
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 |
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 get_node_with_parent(self, data):
parent = None
current = self.root_node
if current == None:
return (parent, None)
while current:
if data == current.data:
return (parent, current)
elif data <= current.data:
parent = current
current = current.left_child
else:
parent = current
current = current.right_child
return (parent, current)
def remove(self, data):
# 1. User helper function to get pointers to node to delete and its parent
parent, node = self.get_node_with_parent(data)
if node == None:
return False
# 2. Get children count of node to delete
children_count = 0
if node.left_child and node.right_child:
children_count = 2
elif (node.left_child is None) and (node.right_child is None):
children_count = 0
else:
children_count = 1
# ????????????????????????????????????????????????????????????????????????????????????????
# ????????????????????????????????????????????????????????????????????????????????????????
??????????????????????????????????????????????????????????????????????????????????????????
??????????????????????????????????????????????????????????????????????????????????????
??????????????????????????????????????????????????????????????????????????????????
??????????????????????????????????????????????????????????????????????????????
??????????????????????????????????????????????????????????????????????????????????
??????????????????????????????????????????????????????????????????????????????
??????????????????????????????????????????????????????????????????????????????????????
??????????????????????????????????????????????????????????????????????????????????
# 4. If node to delete has one child, get pointer to that child (next_node), and if parent exists (i.e. not root case!),
# make parent p
...
if children_count == 0:
if parent:
if parent.right_child is node:
parent.right_child = None
else:
parent.left_child = None
else:
self.root_node = None
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 |
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 get_node_with_parent(self, data):
parent = None
current = self.root_node
if current == None:
return (parent, None)
while current:
if data == current.data:
return (parent, current)
elif data <= current.data:
parent = current
current = current.left_child
else:
parent = current
current = current.right_child
return (parent, current)
def remove(self, data):
# 1. User helper function to get pointers to node to delete and its parent
parent, node = self.get_node_with_parent(data)
if node == None:
return False
# 2. Get children count of node to delete
children_count = 0
if node.left_child and node.right_child:
children_count = 2
elif (node.left_child is None) and (node.right_child is None):
children_count = 0
else:
children_count = 1
# 3. If node to delete has no children, see if its right or left child of parent and act accordingly (cover case of root/
# no parent!)
if children_count == 0:
if parent:
if parent.right_child is node:
parent.right_child = None
else:
parent.left_child = None
else:
self.root_node = None
???????????????????????????????????????????????????????????????????????????????????????
???????????????????????????????????????????????????????????????????????????????????????
???????????????????????????????????????????????????????????????????????????????????
???????????????????????????????????????????????????????????????????????????????????
???????????????????????????????????????????????????????????????????????????????
???????????????????????????????????????????????????????????????????????????????????
???????????????????????????????????????????????????????????????????????????????
???????????????????????????????????????????????????????????????????????????????????
???????????????????
...
elif children_count == 1:
next_node = None
if node.left_child:
next_node = node.left_child
else:
next_node = node.right_child
if parent:
if parent.left_child is node:
parent.left_child = next_node
else:
parent.right_child = next_node
else:
self.root_node = next_node
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 |
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 get_node_with_parent(self, data):
parent = None
current = self.root_node
if current == None:
return (parent, None)
while current:
if data == current.data:
return (parent, current)
elif data <= current.data:
parent = current
current = current.left_child
else:
parent = current
current = current.right_child
return (parent, current)
def remove(self, data):
# 1. User helper function to get pointers to node to delete and its parent
parent, node = self.get_node_with_parent(data)
if node == None:
return False
# 2. Get children count of node to delete
children_count = 0
if node.left_child and node.right_child:
children_count = 2
elif (node.left_child is None) and (node.right_child is None):
children_count = 0
else:
children_count = 1
# 3. If node to delete has no children, see if its right or left child of parent and act accordingly (cover case of root/
# no parent!)
if children_count == 0:
if parent:
if parent.right_child is node:
parent.right_child = None
else:
parent.left_child = None
else:
self.root_node = None
# 4. If node to delete has one child, get pointer to that child (next_node), and if parent exists (i.e. not root case!),
# make parent point correctly (via left/right pointer) to that child, then cover root case (i.e. make root the
# next_node)
elif children_count == 1:
next_node = None
if node.left_child:
next_node = node.left_child
else:
next_node = node.right_child
if parent:
if parent.left_child is node:
parent.left_child = next_node
else:
parent.right_child = next_node
else:
...
else:
parent_of_leftmost_node = node
leftmost_node = node.right_child
while leftmost_node.left_child:
parent_of_leftmost_node = leftmost_node
leftmost_node = leftmost_node.left_child
node.data = leftmost_node.data
if parent_of_leftmost_node.left_child == leftmost_node:
parent_of_leftmost_node.left_child = leftmost_node.right_child
else: ############ parent_of_leftmost_node is root!!
parent_of_leftmost_node.right_child = leftmost_node.right_child
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 |
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 get_node_with_parent(self, data):
parent = None
current = self.root_node
if current == None:
return (parent, None)
while current:
if data == current.data:
return (parent, current)
elif data <= current.data:
parent = current
current = current.left_child
else:
parent = current
current = current.right_child
return (parent, current)
def remove(self, data):
# 1. User helper function to get pointers to node to delete and its parent
parent, node = self.get_node_with_parent(data)
if node == None:
return False
# 2. Get children count of node to delete
children_count = 0
if node.left_child and node.right_child:
children_count = 2
elif (node.left_child is None) and (node.right_child is None):
children_count = 0
else:
children_count = 1
# 3. If node to delete has no children, see if its right or left child of parent and act accordingly (cover case of root/
# no parent!)
if children_count == 0:
if parent:
if parent.right_child is node:
parent.right_child = None
else:
parent.left_child = None
else:
self.root_node = None
# 4. If node to delete has one child, get pointer to that child (next_node), and if parent exists (i.e. not root case!),
# make parent point correctly (via left/right pointer) to that child, then cover root case (i.e. make root the
# next_node)
elif children_count == 1:
next_node = None
if node.left_child:
next_node = node.left_child
else:
next_node = node.right_child
if parent:
if parent.left_child is node:
parent.left_child = next_node
else:
parent.right_child = next_node
else:
...
else:
parent_of_leftmost_node = node
leftmost_node = node.right_child
while leftmost_node.left_child: ##<<<<<<<<<<<<<<<<<<<<<<<<
parent_of_leftmost_node = leftmost_node ##<<<<<<<<<<<<<<<<<<<<<<<<
leftmost_node = leftmost_node.left_child ##<<<<<<<<<<<<<<<<<<<<<<<<
node.data = leftmost_node.data ##<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
if parent_of_leftmost_node.left_child == leftmost_node:
parent_of_leftmost_node.left_child = leftmost_node.right_child
else: ############ parent_of_leftmost_node is root!!
parent_of_leftmost_node.right_child = leftmost_node.right_child
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 |