2026-rff_mp/lukovnikovde/docs/data/DataStructure.py

33 lines
1.0 KiB
Python

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