diff --git a/BudakovIS/docs/LinkedListPhoneBook.py b/BudakovIS/docs/LinkedListPhoneBook.py index bab135a..10f1ec8 100644 --- a/BudakovIS/docs/LinkedListPhoneBook.py +++ b/BudakovIS/docs/LinkedListPhoneBook.py @@ -119,7 +119,7 @@ print(ll_list_all(head)) print("====== END ======") - +#============================== HASH FUNCTIONS ========================= SIZE = 5 buckets = [None] * SIZE @@ -201,3 +201,38 @@ print("search Boris = ",ht_find(buckets, "Boris")) # None # Все записи print("list all records: ",ht_list_all(buckets)) +print("====== END GLOBAL TEST ======\n\n\n") + + + +# ======================== TREE FUNC ==================== + +def create_node(name,phone): + return {'name': name, 'phone': phone, 'left': None, 'right': None} + +print("====== START TREE FUNC CHAPTER ======\n\n") +print("====== TEST CREATE NODE FUNC ======") +root = create_node('Ivan', '123-456') +print("Create Ivan node: ",root) +print("====== END TEST ====== \n\n\n") + +def bst_insert(root, name, phone): + if root is None: + return create_node(name, phone) + + if name == root['name']: + root[phone] = phone + elif name < root['name']: + root['left'] = bst_insert(root['left'], name, phone) + elif name >= root['name']: + root['right'] = bst_insert(root['right'], name , phone) + return root + +print("====== TEST INSERT FUNC ======") +root = bst_insert(root, 'Dima', '456-789') +print("add Dima: ", root) +root = bst_insert(root, 'Boris', '789-123') +print("add Boris: ", root) +root = bst_insert(root, 'Eva', '321-123') +print("add Eva: ", root) +print("====== END TEST =======\n\n\n")