Обновить lukovnikovde/docs/data/DataStructure.py

[0] add a function ll_insert
This commit is contained in:
lukovnikovde 2026-04-10 04:26:53 +00:00
parent 8b4083725b
commit 2f56564cd9

View File

@ -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 ================')