From a95db6edf31b0aafe204de2c98b43458095b1abf Mon Sep 17 00:00:00 2001 From: volkovva Date: Sun, 24 May 2026 23:28:20 +0300 Subject: [PATCH] =?UTF-8?q?=20=D0=BF=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=20=D0=B7=D0=BD?= =?UTF-8?q?=D0=B0=D1=87=D0=B5=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VolkovVA/cod.py | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/VolkovVA/cod.py b/VolkovVA/cod.py index 8383cb1..af9ea4a 100644 --- a/VolkovVA/cod.py +++ b/VolkovVA/cod.py @@ -24,6 +24,7 @@ def ll_insert(head, name, phone): return head def ll_find(head, name): + current = head while current is not None: if current['name'] == name: @@ -32,6 +33,7 @@ def ll_find(head, name): return None def ll_delete(head, name): + if head is None: return None if head['name'] == name: @@ -46,6 +48,7 @@ def ll_delete(head, name): return head def sort_records(lst): + n = len(lst) for i in range(n): for j in range(0, n-i-1): @@ -63,10 +66,11 @@ def ll_list_all(head): return res -# 2. ХЕШ-ТАБЛИЦА +# ХЕШ-ТАБЛИЦА def def_hash(name, size): + hash_value = 0 for char in name: hash_value += ord(char) @@ -274,9 +278,13 @@ if __name__ == '__main__': s_del += time_del results.append(["LinkedList", mode_name, "удаление", time_del]) - print(f"LinkedList ({mode_name}) - Вставка: {s_ins/5:.5f} сек.") - print(f"LinkedList ({mode_name}) - Поиск: {s_fnd/5:.5f} сек.") - print(f"LinkedList ({mode_name}) - Удаление: {s_del/5:.5f} сек.") + print(f" Связный список ({mode_name}) | Среднее за 5 замеров ") + print(f"Вставка: {s_ins/5:.5f} сек.") + print(f"Поиск: {s_fnd/5:.5f} сек.") + print(f"Удаление: {s_del/5:.5f} сек.") + print("-" * 40) + + # ХЕШ-ТАБЛИЦА @@ -311,10 +319,11 @@ if __name__ == '__main__': s_del += time_del results.append(["HashTable", mode_name, "удаление", time_del]) - print(f"HashTable ({mode_name}) - Вставка: {s_ins/5:.5f} сек.") - print(f"HashTable ({mode_name}) - Поиск: {s_fnd/5:.5f} сек.") - print(f"HashTable ({mode_name}) - Удаление: {s_del/5:.5f} сек.") - + print(f" Хеш-таблица ({mode_name}) | Среднее за 5 замеров ") + print(f"Вставка: {s_ins/5:.5f} сек.") + print(f"Поиск: {s_fnd/5:.5f} сек.") + print(f"Удаление: {s_del/5:.5f} сек.") + print("-" * 40) # ДЕРЕВО @@ -333,7 +342,7 @@ if __name__ == '__main__': s_ins += time_ins results.append(["BST", mode_name, "вставка", time_ins]) - + t1 = time.perf_counter() for name in s_names: bst_find(bst, name) @@ -349,10 +358,12 @@ if __name__ == '__main__': s_del += time_del results.append(["BST", mode_name, "удаление", time_del]) - print(f"BST ({mode_name}) - Вставка: {s_ins/5:.5f} сек.") - print(f"BST ({mode_name}) - Поиск: {s_fnd/5:.5f} сек.") - print(f"BST ({mode_name}) - Удаление: {s_del/5:.5f} сек.") - + print(f"Двоичное дерево ({mode_name}) | Среднее за 5 замеров ") + print(f"Вставка: {s_ins/5:.5f} сек.") + print(f"Поиск: {s_fnd/5:.5f} сек.") + print(f"Удаление: {s_del/5:.5f} сек.") + print("-" * 40) + # Сохранение результатов with open("docs/data/results.csv", "w", newline="", encoding="utf-8") as f: writer = csv.writer(f) writer.writerows(results) \ No newline at end of file