From 6916bf235cd78da3a31e182ad104d41452fd39aa Mon Sep 17 00:00:00 2001 From: IvanBud123 Date: Sat, 28 Feb 2026 04:08:41 +0300 Subject: [PATCH] [1] implemented the ll_insert function for an first exercise --- BudakovIS/docs/LinkedListPhoneBook.py | 52 +++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 BudakovIS/docs/LinkedListPhoneBook.py diff --git a/BudakovIS/docs/LinkedListPhoneBook.py b/BudakovIS/docs/LinkedListPhoneBook.py new file mode 100644 index 0000000..a1253f6 --- /dev/null +++ b/BudakovIS/docs/LinkedListPhoneBook.py @@ -0,0 +1,52 @@ +head = None + +#node1 = {'name' : 'Ivan', 'phone' : '123-456', 'next' : None} +#head = node1 + +#node2 = {'name' : 'Dima', 'phone' : '789-123', 'next' : None} +#node1['next'] = node2 + +def ll_insert(head, name, phone): + + curent = head + while curent is not None: + if curent['name'] == name: + curent['phone'] = phone + return head + curent = curent['next'] + + + n_node = {'name' : name, 'phone' : phone, 'next' : None} + + if head is None: + return n_node + + curent = head + while curent['next'] is not None: + curent = curent['next'] + curent['next'] = n_node + return head + + + +ptiny("====== TESTING ll_insert FUNC ========") +head = ll_insert(head,'Ivan','123-456') + +print(head) + +head = ll_insert(head, 'Boris', '123-456') + +print(head) + +head = ll_insert(head, 'Ivan', '321-654') + +print(head) + +head = ll_insert(head, 'Dima', '345-678') + +print(head) + +head = ll_insert(head, 'Boris', '111-222') + +print(head) +print("======= END TEST =======")