[1] ll_func

This commit is contained in:
yanyaevaa 2026-04-25 16:37:33 +03:00
parent de62717491
commit db1243ce91

40
YanyaevAA/[1].py Normal file
View File

@ -0,0 +1,40 @@
def ll_create_node(name, phone):
return {'name': name, 'phone': phone, 'next': None}
def ll_insert(head, name, phone):
current = head
while current:
if current['name'] == name:
current['phone'] = phone
return head
current = current['next']
new_node = ll_create_node(name, phone)
new_node['next'] = head
return new_node
def ll_find(head, name):
current = head
while current:
if current['name'] == name:
return current['phone']
current = current['next']
return None
def ll_delete(head, name):
if head['name'] == name:
return head['next']
current = head
while current['next']:
if current['next']['name'] == name:
current['next'] = current['next']['next']
break
current = current['next']
return head
def ll_list_all(head):
items = []
current = head
while current:
items.append((current['name'], current['phone']))
current = current['next']
return sorted(items) # Сортировка O(N log N)