From b4f085d0f9d22e1de996e748153ea72c645844f3 Mon Sep 17 00:00:00 2001 From: konnovaea Date: Sun, 19 Apr 2026 19:38:18 +0300 Subject: [PATCH] =?UTF-8?q?=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=20=D1=81=D0=B2=D1=8F=D0=B7=D0=BD=D1=8B=D0=B9?= =?UTF-8?q?=20=D1=81=D0=BF=D0=B8=D1=81=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- konnovaea/phonebook.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 konnovaea/phonebook.py diff --git a/konnovaea/phonebook.py b/konnovaea/phonebook.py new file mode 100644 index 0000000..2064305 --- /dev/null +++ b/konnovaea/phonebook.py @@ -0,0 +1,40 @@ +def ll_insert(head, name, phone): + current = head + while current is not None: + if current['name'] == name: + current['phone'] = phone + return head + current = current['next'] + + new_node = {'name': name, 'phone': phone, 'next': head} + return new_node + +def ll_find(head, name): + current = head + while current is not None: + 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'] is not None: + if current['next']['name'] == name: + current['next'] = current['naext']['next'] + return head + current = current['next'] + return head +def ll_list_all(head): + records = [] + current = head + + while current is not None: + records.append((current['name'], current['phine'])) + current = current['next'] + records.sort(key=lambda x: x[0]) + return records