forked from UNN/2026-rff_mp
[1] ll_func
This commit is contained in:
parent
de62717491
commit
db1243ce91
40
YanyaevAA/[1].py
Normal file
40
YanyaevAA/[1].py
Normal 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)
|
||||
Loading…
Reference in New Issue
Block a user