forked from UNN/2026-rff_mp
[1] 1-st-exercise #2
|
|
@ -18,3 +18,39 @@ def ll_insert(head, name, phone):
|
||||||
new_node['next'] = head
|
new_node['next'] = head
|
||||||
return new_node
|
return new_node
|
||||||
|
|
||||||
|
def ll_find(head, name):
|
||||||
|
current = head
|
||||||
|
while current is not None:
|
||||||
|
if current['name']==name:
|
||||||
|
return current['phone']
|
||||||
|
current=current['next']
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def ll_delete(head, name):
|
||||||
|
if head is None:
|
||||||
|
return None
|
||||||
|
if head['name']==name:
|
||||||
|
return head['next']
|
||||||
|
|
||||||
|
current = head
|
||||||
|
while current['next'] is not None:
|
||||||
|
if current['next']['name'] == name:
|
||||||
|
current['next']==current['next']['next']
|
||||||
|
return head
|
||||||
|
|
||||||
|
|
||||||
|
def ll_list_all(head):
|
||||||
|
record=[]
|
||||||
|
current=head
|
||||||
|
while current is not None:
|
||||||
|
record.append(current['name'], current['phone'])
|
||||||
|
current=current['next']
|
||||||
|
record.sort(key=lambda x: x[0])
|
||||||
|
return record
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user