2026-rff_mp/svetlakovkyu/docs/data/01/codes/LL.py
2026-04-13 13:24:59 +03:00

47 lines
1.2 KiB
Python

def ll_insert(head, name, phone):
current = head
while current is not None:
if current['name'] == name:
current['phone'] = phone
return head
current = current['next']
return {'name': name, 'phone': phone, 'next': head}
# проверка
# my_list = None
# my_list = ll_insert(my_list, "Ivan", "555")
# my_list = ll_insert(my_list, "An", "666")
# print(my_list)
def ll_find(head, name):
current = head
while current is not None:
if current['name'] == name:
return current['phone']
current = current['next']
return None
# print(ll_find(my_list,"An"))
# buskets = [None]*10
# print(buskets)
def ll_delete(head, name):
if head is None:
return None
current = head
if head['name'] == name:
return head['next']
while current['next'] is not None:
if current['next']['name'] == name:
current['next'] = current['next']['next']
break
current = current['next']
return head
def ll_list_all(head):
res = []
current = head
while current is not None:
res.append((current['name'], current['phone']))
current = current['next']
res.sort()
return res