2026-rff_mp/MininaVD/docs/data/Laba1dop.doc
2026-03-22 18:53:04 +03:00

21 lines
506 B
Plaintext

Linked List Phone Book:
def ll_insert(head, name, phone):
new_node = {'name': name, 'phone' : phone, 'next': None}
if head is None:
return new_node
if head['name'] == name:
head['phone'] = phone
return head
current = head
while current['next'] is not None:
if current['next']['name'] == name:
current['next']['phone'] = phone
return head
current = current['next']
current['next'] = new_node
return head