From b984ec3569ecac0072c123e045274545aa903d82 Mon Sep 17 00:00:00 2001 From: oSTEVEo Date: Fri, 20 Mar 2026 22:04:02 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=BC=D0=B5=D1=89?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20=D0=B8=20?= =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D1=80?= =?UTF-8?q?=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20Linked?= =?UTF-8?q?List?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MusinAA/task-1/LinkedList.py | 25 -------- MusinAA/task1/__init__.py | 0 .../structures}/BinaryTree.py | 0 .../{task-1 => task1/structures}/HashTable.py | 0 MusinAA/task1/structures/LinkedList.py | 60 +++++++++++++++++++ MusinAA/task1/structures/__init__.py | 0 6 files changed, 60 insertions(+), 25 deletions(-) delete mode 100644 MusinAA/task-1/LinkedList.py create mode 100644 MusinAA/task1/__init__.py rename MusinAA/{task-1 => task1/structures}/BinaryTree.py (100%) rename MusinAA/{task-1 => task1/structures}/HashTable.py (100%) create mode 100644 MusinAA/task1/structures/LinkedList.py create mode 100644 MusinAA/task1/structures/__init__.py diff --git a/MusinAA/task-1/LinkedList.py b/MusinAA/task-1/LinkedList.py deleted file mode 100644 index c9dd29f..0000000 --- a/MusinAA/task-1/LinkedList.py +++ /dev/null @@ -1,25 +0,0 @@ -""" -Связный список (LinkedListPhoneBook) - -Узел представляется словарём: -{'name': 'Имя', 'phone': '123', 'next': None}. -""" - - - -def ll_insert(head, name, phone): - """ - Проходит до конца (или сразу добавляет в конец) и возвращает новую - голову (если вставка в начало) или изменяет список по ссылке. - Удобнее возвращать новую голову, если вставка может быть в начало. - """ - -def ll_find(head, name): - """Ищет узел, возвращает телефон или None.""" - -def ll_delete(head, name): - """Удаляет узел, возвращает новую голову.""" - -def ll_list_all(head): - """Cобирает все записи в список и сортирует. - сортировка вынесена отдельно).""" \ No newline at end of file diff --git a/MusinAA/task1/__init__.py b/MusinAA/task1/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/MusinAA/task-1/BinaryTree.py b/MusinAA/task1/structures/BinaryTree.py similarity index 100% rename from MusinAA/task-1/BinaryTree.py rename to MusinAA/task1/structures/BinaryTree.py diff --git a/MusinAA/task-1/HashTable.py b/MusinAA/task1/structures/HashTable.py similarity index 100% rename from MusinAA/task-1/HashTable.py rename to MusinAA/task1/structures/HashTable.py diff --git a/MusinAA/task1/structures/LinkedList.py b/MusinAA/task1/structures/LinkedList.py new file mode 100644 index 0000000..54850ad --- /dev/null +++ b/MusinAA/task1/structures/LinkedList.py @@ -0,0 +1,60 @@ +""" +Связный список (LinkedListPhoneBook) + +Узел представляется словарём: +{'name': 'Имя', 'phone': '123', 'next': None}. +""" + + +def ll_insert(head : dict|None, name: str, phone: str) -> dict: + """ + Проходит до конца (или сразу добавляет в конец) и возвращает новую + голову (если вставка в начало) или изменяет список по ссылке. + Удобнее возвращать новую голову, если вставка может быть в начало. + """ + + newNode = {'name': name, 'phone': phone, 'next': None} + if head == None: + return newNode + + currentNode = head + while currentNode['next'] != None: + currentNode = currentNode['next'] + currentNode['next'] = newNode + return head + +def ll_find(head : dict|None, name: str) -> str|None: + """Ищет узел, возвращает телефон или None.""" + currentNode = head + while currentNode != None: + if currentNode['name'] == name: + return currentNode['phone'] + currentNode = currentNode['next'] + return None + +def ll_delete(head : dict|None, name: str) -> dict: + """Удаляет узел, возвращает новую голову.""" + if head == None: + return None + + if head['name'] == name: + return head['next'] + + currentNode = head + while currentNode['next'] != None: + if currentNode['next']['name'] == name: + currentNode['next'] = currentNode['next']['next'] + return head + currentNode = currentNode['next'] + return head + +def ll_list_all(head: dict|None) -> list: + """Cобирает все записи в список и сортирует. + сортировка вынесена отдельно).""" + records = [] + currentNode = head + while currentNode != None: + records.append((currentNode['name'], currentNode['phone'])) + currentNode = currentNode['next'] + records.sort(key=lambda item: item[0]) + return records \ No newline at end of file diff --git a/MusinAA/task1/structures/__init__.py b/MusinAA/task1/structures/__init__.py new file mode 100644 index 0000000..e69de29