From 054035deac47ee5b14de00098a179103b4e62910 Mon Sep 17 00:00:00 2001 From: ivanchenkoam Date: Sat, 23 May 2026 15:52:49 +0300 Subject: [PATCH] =?UTF-8?q?[1]=20=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8F=20=D1=81=D0=B2=D1=8F=D0=B7=D0=BD=D0=BE?= =?UTF-8?q?=D0=B3=D0=BE=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 --- ivanchenkoam/laba1.txt | 63 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/ivanchenkoam/laba1.txt b/ivanchenkoam/laba1.txt index 2b5ab87..b04fdb5 100644 --- a/ivanchenkoam/laba1.txt +++ b/ivanchenkoam/laba1.txt @@ -5,4 +5,65 @@ import sys from typing import List, Tuple, Optional, Any, Dict #лимит рекурсии -sys.setrecursionlimit(20000) \ No newline at end of file +sys.setrecursionlimit(20000) +def ll_insert(head: Optional[Dict], name: str, phone: str) -> Dict: + """Вставка в конец связного списка""" + new_node = {'name': name, 'phone': phone, 'next': None} + + if head is None: + return new_node + + current = head + while current['next'] is not None: + # Обновляем, если уже есть + if current['name'] == name: + current['phone'] = phone + return head + current = current['next'] + + if current['name'] == name: + current['phone'] = phone + else: + current['next'] = new_node + + return head + + +def ll_find(head: Optional[Dict], name: str) -> Optional[str]: + """Поиск в связном списке""" + current = head + while current is not None: + if current['name'] == name: + return current['phone'] + current = current['next'] + return None + + +def ll_delete(head: Optional[Dict], name: str) -> Optional[Dict]: + """Удаление из связного списка""" + 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: Optional[Dict]) -> List[Tuple[str, str]]: + """Сбор всех записей из связного списка с сортировкой""" + 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