From b07adc7cb4fd66be1ed555b48627e8536a6c7769 Mon Sep 17 00:00:00 2001 From: komissarovgo Date: Sun, 26 Apr 2026 00:23:49 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8F=20=D1=81=D0=B2=D1=8F=D0=B7=D0=BD=D0=BE=D0=B3=D0=BE?= =?UTF-8?q?=20=D1=81=D0=BF=D0=B8=D1=81=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- komissarovgo/docs/data/CodePhoneBook.py | 64 ++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/komissarovgo/docs/data/CodePhoneBook.py b/komissarovgo/docs/data/CodePhoneBook.py index 8bb29ad..77d0fac 100644 --- a/komissarovgo/docs/data/CodePhoneBook.py +++ b/komissarovgo/docs/data/CodePhoneBook.py @@ -1,4 +1,66 @@ import time import random import csv -import sys \ No newline at end of file +import sys + +# 1. LinkedList + +def ll_insert(head, name, phone): + + new_node = {'name': name, 'phone': phone, 'next': None} + + if head is None: + return new_node + + if head['name'] == name: + head['phone'] = phone + return head + + current = head + while current['next'] is not None: + if current['next']['name'] == name: + current['next']['phone'] = phone + return head + current = current['next'] + + current['next'] = new_node + return head + + +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['next']['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['phone'])) + current = current['next'] + records.sort(key=lambda x: x[0]) + return records \ No newline at end of file