diff --git a/lukovnikovde/docs/data/DataStructure.py b/lukovnikovde/docs/data/DataStructure.py index e69de29..dae6e2c 100644 --- a/lukovnikovde/docs/data/DataStructure.py +++ b/lukovnikovde/docs/data/DataStructure.py @@ -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 ================')