def show_layout(layout, keys): from naive import NaiveBST from treeview import TreeView t = NaiveBST() tv = TreeView(t, layout_algorithm=layout) for key in keys: t.insert(key) tv.view()
def usage(): import random random.seed(0) # do always the same for testing # tree = NaiveBST() # print(tree) # print() # tree.insert(2) # print(tree) # print() # tree.insert(1) # print(tree) # print() # tree.insert(3) # print(tree) # print() # print("Random insertions") # tree = NaiveBST() # for i in range(10): # n = random.randint(1,20) # print("insert", n) # tree.insert(n) # print(tree, end="\n\n") tree = NaiveBST() n = 16 universe = list(range(n)) random.shuffle(universe) for key in universe: tree.insert(key) # print(tree) # print(tree.preorder()) node5 = tree.root.left node5.rotate() print(tree) # print(' '.join([str(key) for key in tree.preorder()])) from treeview import TreeView tv = TreeView(tree) tv.view() tree.root.right.rotate() tv.view() print(tree.search_functional(4))
def join(): t = NaiveBST() t.insert(7) t.insert(4) t.insert(2) t.insert(6) t.insert(1) t.insert(3) t.insert(5) t.insert(9) t.insert(8) t.insert(10) from viewer.treeview import TreeView tv = TreeView(t) tv.view() p = t.root p.left.rotate() tv.view() p.left.rotate() tv.view()