Skip to content
Snippets Groups Projects
Commit 94870ad9 authored by florian.burgener's avatar florian.burgener
Browse files

Refactoring

parent b4f49d51
No related branches found
No related tags found
No related merge requests found
......@@ -37,18 +37,23 @@ def array_insert_sorted(array, value):
return index
def insert(root, key):
leaf_node = root
def find_leaf(root, key):
parents = []
while not leaf_node.is_leaf:
parents.append(leaf_node)
index = array_binary_search(leaf_node.keys, key)
leaf_node = leaf_node.children[index]
current = root
while not current.is_leaf:
parents.append(current)
children_index = array_binary_search(current.keys, key)
current = current.children[children_index]
return parents, current
def insert(root, key):
parents, leaf = find_leaf(root, key)
if node_is_full(leaf_node):
insert_full(root, parents, leaf_node, key, None)
if node_is_full(leaf):
insert_full(root, parents, leaf, key, None)
else:
insert_non_full(leaf_node, key, None)
insert_non_full(leaf, key, None)
def insert_non_full(node, key, right_child_node):
......@@ -156,8 +161,6 @@ def increase_height(root, key, right_child_node):
def tree_print(root, depth=0):
if len(root.keys) == 0:
return
print(" " * depth, end="")
print(root.keys)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment