-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathChaining.py
36 lines (30 loc) · 892 Bytes
/
Chaining.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from LinkedList import LinkedList
class HashChain:
def __init__(self):
self.hashtable_size = 10
self.hashtable = [0] * self.hashtable_size
for i in range(self.hashtable_size):
self.hashtable[i] = LinkedList()
def hashcode(self, key):
return key % self.hashtable_size
def insert(self, element):
i = self.hashcode(element)
self.hashtable[i].insertsorted(element)
def search(self, key):
i = self.hashcode(key)
return self.hashtable[i].search(key) != -1
def display(self):
for i in range(self.hashtable_size):
print('[',i,']',end=' ')
self.hashtable[i].display()
print()
H = HashChain()
H.insert(54)
H.insert(78)
H.insert(64)
H.insert(92)
H.insert(34)
H.insert(86)
H.insert(28)
H.display()
print('Result:',H.search(74))