From 8a5904376cf2abbcffbed845421afa3af13aa5d5 Mon Sep 17 00:00:00 2001 From: IvanBud123 Date: Sat, 28 Feb 2026 04:47:27 +0300 Subject: [PATCH] [2] adding ll_find and ll_delete --- BudakovIS/docs/LinkedListPhoneBook.py | 43 +++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/BudakovIS/docs/LinkedListPhoneBook.py b/BudakovIS/docs/LinkedListPhoneBook.py index a1253f6..4e1507d 100644 --- a/BudakovIS/docs/LinkedListPhoneBook.py +++ b/BudakovIS/docs/LinkedListPhoneBook.py @@ -29,7 +29,7 @@ def ll_insert(head, name, phone): -ptiny("====== TESTING ll_insert FUNC ========") +print("====== TESTING ll_insert FUNC ========") head = ll_insert(head,'Ivan','123-456') print(head) @@ -49,4 +49,43 @@ print(head) head = ll_insert(head, 'Boris', '111-222') print(head) -print("======= END TEST =======") +print(f"======= END TEST =======\n\n\n") + + +def ll_find(head, name): + curent = head + while curent is not None: + if curent['name'] == name: + return curent['phone'] + curent = curent['next'] + return None + +print("====== TESTING ll_find FUNC ======") + +print("Ivan`s phone: "+ ll_find(head, 'Ivan')) + +print("Dima`s phone: "+ ll_find(head, 'Dima')) + +print("Boris phone: "+ ll_find(head, 'Boris')) + +print(f"====== END TEST ======\n\n\n") + + +def ll_delete(head, name): + if head is None: + return None + + if head['name'] == name: + return head['next'] + + prev = head + curent = head['next'] + while curent is not None: + if curent['name'] == name: + prev['next'] = curent['next'] + return head + prev = curent + curent = curent['next'] + return head + +print("Del of Dima:", ll_delete(head, 'Dima'))