[2] adding ll_find and ll_delete
This commit is contained in:
parent
ba244f24bb
commit
050462d011
|
|
@ -29,7 +29,7 @@ def ll_insert(head, name, phone):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ptiny("====== TESTING ll_insert FUNC ========")
|
print("====== TESTING ll_insert FUNC ========")
|
||||||
head = ll_insert(head,'Ivan','123-456')
|
head = ll_insert(head,'Ivan','123-456')
|
||||||
|
|
||||||
print(head)
|
print(head)
|
||||||
|
|
@ -49,4 +49,43 @@ print(head)
|
||||||
head = ll_insert(head, 'Boris', '111-222')
|
head = ll_insert(head, 'Boris', '111-222')
|
||||||
|
|
||||||
print(head)
|
print(head)
|
||||||
print("======= END TEST =======")
|
print(f"======= END TEST =======\n\n\n")
|
||||||
|
|
||||||
|
|
||||||
|
def ll_find(head, name):
|
||||||
|
curent = head
|
||||||
|
while curent is not None:
|
||||||
|
if curent['name'] == name:
|
||||||
|
return curent['phone']
|
||||||
|
curent = curent['next']
|
||||||
|
return None
|
||||||
|
|
||||||
|
print("====== TESTING ll_find FUNC ======")
|
||||||
|
|
||||||
|
print("Ivan`s phone: "+ ll_find(head, 'Ivan'))
|
||||||
|
|
||||||
|
print("Dima`s phone: "+ ll_find(head, 'Dima'))
|
||||||
|
|
||||||
|
print("Boris phone: "+ ll_find(head, 'Boris'))
|
||||||
|
|
||||||
|
print(f"====== END TEST ======\n\n\n")
|
||||||
|
|
||||||
|
|
||||||
|
def ll_delete(head, name):
|
||||||
|
if head is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if head['name'] == name:
|
||||||
|
return head['next']
|
||||||
|
|
||||||
|
prev = head
|
||||||
|
curent = head['next']
|
||||||
|
while curent is not None:
|
||||||
|
if curent['name'] == name:
|
||||||
|
prev['next'] = curent['next']
|
||||||
|
return head
|
||||||
|
prev = curent
|
||||||
|
curent = curent['next']
|
||||||
|
return head
|
||||||
|
|
||||||
|
print("Del of Dima:", ll_delete(head, 'Dima'))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user