2026-05-23 10:23:41 +00:00
|
|
|
import random as rnd
|
2026-05-23 13:31:09 +00:00
|
|
|
<<<<<<< HEAD
|
2026-05-23 10:23:41 +00:00
|
|
|
|
|
|
|
|
def ll_insert(head, name, phone):
|
|
|
|
|
new_node = {'name': name, 'phone': phone, 'next': None}
|
|
|
|
|
|
|
|
|
|
if head is None:
|
|
|
|
|
return new_node
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
current = head
|
|
|
|
|
while current is not None:
|
|
|
|
|
if current['name'] == name:
|
|
|
|
|
current['phone'] = phone
|
|
|
|
|
return head
|
2026-05-23 13:12:52 +00:00
|
|
|
if current['next'] is None:
|
|
|
|
|
break
|
2026-05-23 10:23:41 +00:00
|
|
|
current = current['next']
|
|
|
|
|
|
2026-05-23 13:12:52 +00:00
|
|
|
current['next'] = new_node
|
|
|
|
|
return head
|
2026-05-23 10:23:41 +00:00
|
|
|
|
2026-05-23 11:47:03 +00:00
|
|
|
def ll_find(head, name):
|
|
|
|
|
current = head
|
|
|
|
|
while current is not None:
|
2026-05-23 13:12:52 +00:00
|
|
|
if current['name'] == name:
|
2026-05-23 11:47:03 +00:00
|
|
|
return current['phone']
|
2026-05-23 13:12:52 +00:00
|
|
|
current = current['next']
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
2026-05-23 11:47:03 +00:00
|
|
|
def ll_delete(head, name):
|
|
|
|
|
if head is None:
|
|
|
|
|
return None
|
2026-05-23 13:12:52 +00:00
|
|
|
if head['name'] == name:
|
2026-05-23 11:47:03 +00:00
|
|
|
return head['next']
|
|
|
|
|
|
2026-05-23 13:12:52 +00:00
|
|
|
current = head
|
2026-05-23 11:47:03 +00:00
|
|
|
while current['next'] is not None:
|
|
|
|
|
if current['next']['name'] == name:
|
2026-05-23 13:12:52 +00:00
|
|
|
current['next'] = current['next']['next']
|
2026-05-23 11:47:03 +00:00
|
|
|
return head
|
2026-05-23 13:12:52 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
2026-05-23 11:47:03 +00:00
|
|
|
def ll_list_all(head):
|
2026-05-23 13:12:52 +00:00
|
|
|
record = []
|
|
|
|
|
current = head
|
2026-05-23 11:47:03 +00:00
|
|
|
while current is not None:
|
2026-05-23 13:12:52 +00:00
|
|
|
record += [(current['name'], current['phone'])]
|
|
|
|
|
current = current['next']
|
|
|
|
|
res = sort_records(record)
|
2026-05-23 13:31:09 +00:00
|
|
|
return res
|
|
|
|
|
=======
|
|
|
|
|
>>>>>>> 221b0dbe36c30826c59c8721814c9bb881eafeee
|