forked from UNN/2026-rff_mp
[1] implemented the ll_insert function for an first exercise
This commit is contained in:
parent
daa53f7395
commit
8459b3a632
52
BudakovIS/docs/LinkedListPhoneBook.py
Normal file
52
BudakovIS/docs/LinkedListPhoneBook.py
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
head = None
|
||||
|
||||
#node1 = {'name' : 'Ivan', 'phone' : '123-456', 'next' : None}
|
||||
#head = node1
|
||||
|
||||
#node2 = {'name' : 'Dima', 'phone' : '789-123', 'next' : None}
|
||||
#node1['next'] = node2
|
||||
|
||||
def ll_insert(head, name, phone):
|
||||
|
||||
curent = head
|
||||
while curent is not None:
|
||||
if curent['name'] == name:
|
||||
curent['phone'] = phone
|
||||
return head
|
||||
curent = curent['next']
|
||||
|
||||
|
||||
n_node = {'name' : name, 'phone' : phone, 'next' : None}
|
||||
|
||||
if head is None:
|
||||
return n_node
|
||||
|
||||
curent = head
|
||||
while curent['next'] is not None:
|
||||
curent = curent['next']
|
||||
curent['next'] = n_node
|
||||
return head
|
||||
|
||||
|
||||
|
||||
ptiny("====== TESTING ll_insert FUNC ========")
|
||||
head = ll_insert(head,'Ivan','123-456')
|
||||
|
||||
print(head)
|
||||
|
||||
head = ll_insert(head, 'Boris', '123-456')
|
||||
|
||||
print(head)
|
||||
|
||||
head = ll_insert(head, 'Ivan', '321-654')
|
||||
|
||||
print(head)
|
||||
|
||||
head = ll_insert(head, 'Dima', '345-678')
|
||||
|
||||
print(head)
|
||||
|
||||
head = ll_insert(head, 'Boris', '111-222')
|
||||
|
||||
print(head)
|
||||
print("======= END TEST =======")
|
||||
Loading…
Reference in New Issue
Block a user