добавлены функции ht_find ht_delete ht_list_ all

This commit is contained in:
volkovva 2026-05-23 19:49:23 +03:00
parent 759c0eab91
commit c5baf3661a

View File

@ -74,8 +74,31 @@ 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)
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)
def ht_list_all(buckets):
res = []
for head in buckets:
current = head
while current is not None:
res += [(current['name'], current['phone'])]
current = current['next']
return sort_records(res)