forked from UNN/2026-rff_mp
Compare commits
4 Commits
221b0dbe36
...
238245c512
| Author | SHA1 | Date | |
|---|---|---|---|
| 238245c512 | |||
| f589771843 | |||
| 60b42ee51c | |||
| 21985795a1 |
|
|
@ -1 +1,65 @@
|
||||||
import random as rnd
|
import random as rnd
|
||||||
|
<<<<<<< HEAD
|
||||||
|
|
||||||
|
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
|
||||||
|
if current['next'] is None:
|
||||||
|
break
|
||||||
|
current = current['next']
|
||||||
|
|
||||||
|
current['next'] = new_node
|
||||||
|
return head
|
||||||
|
|
||||||
|
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
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
def ll_list_all(head):
|
||||||
|
record = []
|
||||||
|
current = head
|
||||||
|
while current is not None:
|
||||||
|
record += [(current['name'], current['phone'])]
|
||||||
|
current = current['next']
|
||||||
|
res = sort_records(record)
|
||||||
|
return res
|
||||||
|
=======
|
||||||
|
>>>>>>> 221b0dbe36c30826c59c8721814c9bb881eafeee
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user