forked from UNN/2026-rff_mp
вычисление индекса, начало хеш таблицы
This commit is contained in:
parent
238245c512
commit
759c0eab91
|
|
@ -1,5 +1,5 @@
|
||||||
import random as rnd
|
import random as rnd
|
||||||
<<<<<<< HEAD
|
|
||||||
|
|
||||||
def ll_insert(head, name, phone):
|
def ll_insert(head, name, phone):
|
||||||
new_node = {'name': name, 'phone': phone, 'next': None}
|
new_node = {'name': name, 'phone': phone, 'next': None}
|
||||||
|
|
@ -61,5 +61,21 @@ def ll_list_all(head):
|
||||||
current = current['next']
|
current = current['next']
|
||||||
res = sort_records(record)
|
res = sort_records(record)
|
||||||
return res
|
return res
|
||||||
=======
|
|
||||||
>>>>>>> 221b0dbe36c30826c59c8721814c9bb881eafeee
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def def_hash(name, size):
|
||||||
|
hash_value = 0
|
||||||
|
for char in name:
|
||||||
|
hash_value += ord(char)
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user