forked from UNN/2026-rff_mp
Обновить lukovnikovde/docs/data/DataStructure.py
[0] add a function ll_insert
This commit is contained in:
parent
8b4083725b
commit
2f56564cd9
|
|
@ -0,0 +1,33 @@
|
||||||
|
import random as rnd
|
||||||
|
#############################################################################################
|
||||||
|
head = None
|
||||||
|
|
||||||
|
def ll_insert(head, name, phone):
|
||||||
|
next_node = {'name': name, 'phone': phone, 'next': None}
|
||||||
|
if head is None: return next_node
|
||||||
|
|
||||||
|
running = head
|
||||||
|
while running is not None:
|
||||||
|
if running['name'] == name:
|
||||||
|
running['phone'] = phone
|
||||||
|
return head
|
||||||
|
running = running['next']
|
||||||
|
|
||||||
|
running = head
|
||||||
|
while running['next'] is not None: running = running['next']
|
||||||
|
running['next'] = next_node
|
||||||
|
return head
|
||||||
|
|
||||||
|
print('======== TESTING LL_INSERT ==========')
|
||||||
|
Name = ['Dima', 'Ivan', 'Maxim', 'Alex']
|
||||||
|
|
||||||
|
for _ in range(10):
|
||||||
|
name = Name[rnd.randint(0, 3)]
|
||||||
|
phone = str(rnd.randint(0,9)) + str(rnd.randint(0,9)) + str(rnd.randint(0,9)) + '-' + \
|
||||||
|
str(rnd.randint(0,9)) + str(rnd.randint(0,9)) + str(rnd.randint(0,9))
|
||||||
|
print(name, phone)
|
||||||
|
head = ll_insert(head, name, phone)
|
||||||
|
print(head)
|
||||||
|
print('-----------------------------------\n')
|
||||||
|
|
||||||
|
print('======== END TESTING ================')
|
||||||
Loading…
Reference in New Issue
Block a user