From 786881334d4e7d2598166f151587c1774a825db5 Mon Sep 17 00:00:00 2001 From: Maksim Date: Fri, 27 Feb 2026 23:43:40 +0300 Subject: [PATCH 1/2] [0] initial commit --- GorkinMM/425.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 GorkinMM/425.md diff --git a/GorkinMM/425.md b/GorkinMM/425.md new file mode 100644 index 0000000..e69de29 -- 2.43.0 From 601713ddffa92a9f0dc96b53440173ca840f3aa2 Mon Sep 17 00:00:00 2001 From: Maksim Date: Sat, 28 Feb 2026 00:29:35 +0300 Subject: [PATCH 2/2] =?UTF-8?q?[1]=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=201.1.=20?= =?UTF-8?q?=D0=A1=D0=B2=D1=8F=D0=B7=D0=BD=D1=8B=D0=B9=20=D1=81=D0=BF=D0=B8?= =?UTF-8?q?=D1=81=D0=BE=D0=BA=20(LinkedListPhoneBook)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GorkinMM/1.1.py | 73 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 GorkinMM/1.1.py diff --git a/GorkinMM/1.1.py b/GorkinMM/1.1.py new file mode 100644 index 0000000..9c5e9b4 --- /dev/null +++ b/GorkinMM/1.1.py @@ -0,0 +1,73 @@ +def create_node(name, phone): + return {'name': name, 'phone': phone, 'next': None} + +def ll_insert(head, name, phone): + if head is None: + return create_node(name, phone) + + current = head + while True: + if current['name'] == name: + current['phone'] = phone + return head + + if current['next'] is None: + break + current = current['next'] + + current['next'] = create_node(name, phone) + return head + +def ll_find(head, name): + current = head + while current: + if current['name'] == name: + return current['phone'] + current = current['next'] + return None + +def ll_delete(head, name): + if head is None: + return None + + if head['name'] == name: + return head['next'] + + current = head + while current['next']: + if current['next']['name'] == name: + current['next'] = current['next']['next'] + return head + current = current['next'] + + return head + +def ll_list_all(head): + result = [] + current = head + while current: + result.append((current['name'], current['phone'])) + current = current['next'] + result.sort(key=lambda x: x[0]) + return result + +if __name__ == "__main__": + phonebook = None + + phonebook = ll_insert(phonebook, "Коля", "111-11-11") + phonebook = ll_insert(phonebook, "Саша", "222-22-22") + phonebook = ll_insert(phonebook, "Женя", "333-33-33") + + print("После вставки:", ll_list_all(phonebook)) + + phonebook = ll_insert(phonebook, "Коля", "999-99-99") + print("После обновления Коля:", ll_list_all(phonebook)) + + print("Поиск Саша:", ll_find(phonebook, "Саша")) + print("Поиск Zoro:", ll_find(phonebook, "Zoro")) + + phonebook = ll_delete(phonebook, "Саша") + print("Удалили Саша:", ll_list_all(phonebook)) + + phonebook = ll_delete(phonebook, "Коля") + print("Удалили Коля:", ll_list_all(phonebook)) \ No newline at end of file -- 2.43.0