diff --git a/VolkovVA/cod.py b/VolkovVA/cod.py index 971551c..63853b8 100644 --- a/VolkovVA/cod.py +++ b/VolkovVA/cod.py @@ -1,13 +1,15 @@ import random as rnd +# СВЯЗНЫЙ СПИСОК + + def ll_insert(head, name, phone): new_node = {'name': name, 'phone': phone, 'next': None} if head is None: return new_node - - + current = head while current is not None: if current['name'] == name: @@ -28,7 +30,6 @@ def ll_find(head, name): current = current['next'] return None - def ll_delete(head, name): if head is None: return None @@ -43,7 +44,6 @@ def ll_delete(head, name): current = current['next'] return head - def sort_records(lst): n = len(lst) for i in range(n): @@ -52,7 +52,6 @@ def sort_records(lst): lst[j], lst[j + 1] = lst[j + 1], lst[j] return lst - def ll_list_all(head): record = [] current = head @@ -63,8 +62,7 @@ def ll_list_all(head): return res - - +# 2. ХЕШ-ТАБЛИЦА def def_hash(name, size): @@ -74,25 +72,22 @@ def def_hash(name, size): final_idx = hash_value % size return final_idx - def ht_insert(buckets, name, phone): size = len(buckets) idx = def_hash(name, size) - ll_insert(buckets[idx], name, phone) - + buckets[idx] = ll_insert(buckets[idx], name, phone) + return buckets def ht_find(buckets, name): size = len(buckets) idx = def_hash(name, size) return ll_find(buckets[idx], name) - - def ht_delete(buckets, name): size = len(buckets) idx = def_hash(name, size) buckets[idx] = ll_delete(buckets[idx], name) - + return buckets def ht_list_all(buckets): res = [] @@ -104,7 +99,7 @@ def ht_list_all(buckets): return sort_records(res) - +# ДВОИЧНОЕ ДЕРЕВО ПОИСКА def bst_insert(root, name, phone): @@ -131,7 +126,6 @@ def bst_insert(root, name, phone): return root - def bst_find(root, name): current = root while current is not None: @@ -143,7 +137,6 @@ def bst_find(root, name): current = current['right'] return None - def bst_delete(root, name): if root is None: return None @@ -197,7 +190,6 @@ def bst_delete(root, name): p_node['right'] = c_node return root - def bst_list_all(root): record = [] @@ -209,4 +201,30 @@ def bst_list_all(root): helper(node['right']) helper(root) - return record \ No newline at end of file + return record + + +# ЭКСПЕРИМЕНТАЛЬНАЯ ЧАСТЬ + + +if __name__ == '__main__': + N = 10000 + + + records = [] + for i in range(N): + + name = f"User_{i:05d}" + phone = f"+7-{rnd.randint(100, 999)}-{rnd.randint(100, 999)}-{rnd.randint(1000, 9999)}" + records.append((name, phone)) + + + records_shuffled = records[:] + rnd.shuffle(records_shuffled) + + + records_sorted = sorted(records, key=lambda x: x[0]) + + print(f" Бетта-тест") + print(f"records_shuffled (первые 3): {records_shuffled[:3]}") + print(f"records_sorted (первые 3): {records_sorted[:3]}") \ No newline at end of file