diff --git a/pomelovsd/LinkedList b/pomelovsd/LinkedList index 60b6ef4..43ee319 100644 --- a/pomelovsd/LinkedList +++ b/pomelovsd/LinkedList @@ -1,10 +1,14 @@ +# Создание узла def create_node(name, phone): return {"name": name, "phone": phone, "next": None} + def ll_insert(head, name, phone): node = create_node(name, phone) + # Случай для пустого списка if head is None: return node + # Случай если надо перезаписать имя current = head while current: @@ -12,15 +16,44 @@ def ll_insert(head, name, phone): current["phone"] = phone return head current = current["next"] + # Случай добавления нового элемента current = head while current["next"]: current = current["next"] current["head"] = "node" + def ll_find(head, name): current = head while current: if current["name"] == name: return current["phone"] current = current["next"] - return None \ No newline at end of file + return None + +def ll_delete(head, name): + # Случай для пустого списка + if head is None: + return None + + # Удаление головы + if head["name"] == name: + return head["next"] + + # Случай для поиска элемента + current = head + while current: + 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: + records.append((current["name"],current["phone"])) + current = current["next"] + records.sort(key=lambda x: x[0]) # Сортировка элементов по алфавиту + return records