You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
def hash(self, key):
return key % self.size
def add(self, value):
hash = self.hash(value)
if self.elems[hash] is None:
self.elems[hash] = value
else:
i = 1
while True:
index = (hash + i) % self.size
if self.elems[index] is None:
self.elems[index] = value
break
i += 1
def print_ht(self):
output = []
for i in range(self.size):
if self.elems[i] is not None:
output.append(f"{i} -> {self.elems[i]}")
else:
output.append(f"{i} -> ")
print("\n".join(output))
class HashTable:
def init(self, size):
self.elems = [None] * size
self.size = size
ht = HashTable(10)
ht.add(13)
ht.add(73)
ht.add(23)
ht.add(14)
ht.print_ht()
The text was updated successfully, but these errors were encountered: