linked_list

This commit is contained in:
Pavel 2026-05-03 22:59:04 +03:00
parent 2ce10515cd
commit 2f7370eb01

View File

@ -1,12 +1,44 @@
def ll_create_node(name, phone):
return {'name': name, 'phone': phone}
def ll_insert(head, name, phone):
{'name': name, 'phone': phone}
pass
if head is None:
return ll_create_node(name, phone)
current = head
while current:
if current ['name'] == name:
current['phone'] = phone
return head
if current ['next'] is None:
break
current = current['next']
current['next'] = ll_create_node(name, phone)
return head
def ll_find(head, name):
pass
current = head
while current:
if current['name'] == name:
return current['phone']
current = current['next']
return None
def ll_delete(head, name):
pass
if head is None:
return None
if head['name'] == name:
return head['next']
current = head
while current['next']:
if current['next']['name'] == name:
current['next'] = current['next']['next']
return head
def ll_list_all(head):
pass
items = []
current = head
while current:
items.append((current['name'], current['phone']))
current = current['next']
return sorted(items, key=lambda x:x[0])