сделал явную сортировку и исправил недочеты

This commit is contained in:
volkovva 2026-05-23 16:12:52 +03:00
parent 60b42ee51c
commit f589771843

View File

@ -12,45 +12,51 @@ def ll_insert(head, name, phone):
if current['name'] == name: if current['name'] == name:
current['phone'] = phone current['phone'] = phone
return head return head
if current['next'] is None:
break
current = current['next'] current = current['next']
current['next'] = new_node
new_node['next'] = head return head
return new_node
def ll_find(head, name): def ll_find(head, name):
current = head current = head
while current is not None: while current is not None:
if current['name']==name: if current['name'] == name:
return current['phone'] return current['phone']
current=current['next'] current = current['next']
return None return None
def ll_delete(head, name): def ll_delete(head, name):
if head is None: if head is None:
return None return None
if head['name']==name: if head['name'] == name:
return head['next'] return head['next']
current = head current = head
while current['next'] is not None: while current['next'] is not None:
if current['next']['name'] == name: if current['next']['name'] == name:
current['next']==current['next']['next'] current['next'] = current['next']['next']
return head return head
current = current['next']
return head
def sort_records(lst):
n = len(lst)
for i in range(n):
for j in range(0, n-i-1):
if lst[j][0] > lst[j + 1][0]:
lst[j], lst[j + 1] = lst[j + 1], lst[j]
return lst
def ll_list_all(head): def ll_list_all(head):
record=[] record = []
current=head current = head
while current is not None: while current is not None:
record.append(current['name'], current['phone']) record += [(current['name'], current['phone'])]
current=current['next'] current = current['next']
record.sort(key=lambda x: x[0]) res = sort_records(record)
return record return res