diff --git a/BudakovIS/docs/LinkedListPhoneBook.py b/BudakovIS/docs/LinkedListPhoneBook.py index 10f1ec8..0e481ee 100644 --- a/BudakovIS/docs/LinkedListPhoneBook.py +++ b/BudakovIS/docs/LinkedListPhoneBook.py @@ -236,3 +236,85 @@ print("add Boris: ", root) root = bst_insert(root, 'Eva', '321-123') print("add Eva: ", root) print("====== END TEST =======\n\n\n") + + +def bst_find(root, name): + if root is None: + return None + if name == root['name'] + return root['phone'] + elif name root['name']: + root['right'] = bst_delete(root['right'], name) + + else: + if root['left'] is None: + return root['right'] + if root['right'] is None: + return root['rihgt'] + + min_node = find_min(root['right']) + root['name'] = min_node['name'] + root['phone'] = min_node['phone'] + + root['right'] = bst_delete(root['right'], min_node['name']) + return root + + + +def bst_list_all(root): + result = [] + def inorder(node): + if node is None: + return + inorder(node['left']) + result.append((node['name'], node['phone'])) + inorder(node['right']) + inorder(root) + return result + + +print("====== GLOBAL TEST TREES ======") +root = None + +root = bst_insert(root, "Ivan", "123-456") +print("add Ivan: ", root) +root = bst_insert(root, "Boris", "789-012") +print("add Boris: ", root) +root = bst_insert(root, "Anna", "345-678") +print("add Anna: ", root) +root = bst_insert(root, "Ivan", "111-222") # обновление +print("update Ivan: ", root) + +print("Find Ivan`s phone: ",bst_find(root, "Ivan")) # 111-222 +print("Find Peter`s phone: ",bst_find(root, "Petr")) # None + +root = bst_delete(root, "Boris") +print("Del Boris") +print("Find Boris: ",bst_find(root, "Boris")) # None + +print("Find ALL: ",bst_list_all(root)) # [('Anna','345-678'), ('Ivan','111-222')] + + +print("====== END TEST ======") + + +