add ll
This commit is contained in:
parent
566d89fda2
commit
4cb30a7747
46
svetlakovkyu/docs/data/01/codes/LL.py
Normal file
46
svetlakovkyu/docs/data/01/codes/LL.py
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
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
|
||||
Loading…
Reference in New Issue
Block a user