From d51f3fe51e7ad95a9c8493378ffe600e57fc09e5 Mon Sep 17 00:00:00 2001 From: mddcorporation Date: Sat, 21 Mar 2026 15:23:20 +0300 Subject: [PATCH] =?UTF-8?q?now=20with=20hash=F0=9F=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VaravinVV/task1_1.py | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/VaravinVV/task1_1.py b/VaravinVV/task1_1.py index 204a936..06f4567 100644 --- a/VaravinVV/task1_1.py +++ b/VaravinVV/task1_1.py @@ -58,4 +58,42 @@ def ll_list_all(head): data_list.append({'name': current['name'], 'phone': current['phone']}) current = current['next'] data_list.sort(key=lambda x: x['name']) - return data_list \ No newline at end of file + return data_list + + +def hash_function(name, size): + return hash(name) % size + + +def ht_insert(buckets, name, phone): + index = hash_function(name, len(buckets)) + head = buckets[index] + new_head = ll_insert(head, name, phone) + buckets[index] = new_head + return buckets + + +def ht_find(buckets, name): + index = hash_function(name, len(buckets)) + head = buckets[index] + return ll_find(head, name) + + +def ht_delete(buckets, name): + index = hash_function(name, len(buckets)) + head = buckets[index] + new_head = ll_delete(head, name) + buckets[index] = new_head + return buckets + + +def ht_list_all(buckets): + all_records = [] + for head in buckets: + current = head + while current is not None: + all_records.append((current['name'], current['phone'])) + current = current['next'] + all_records.sort(key=lambda x: x[0]) + return all_records +