-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHASH.py
33 lines (30 loc) · 1.16 KB
/
HASH.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
class HASH:
def __init__(self):
self.hash_table = list(None)*20
def hash(self,value):
hash_index = hash(value) % 20
return hash_index
def insert(self,value):
hash_index = self.hash(values)
while self.hash_table[hash_index] is not None:
hash_index = (hash_index+1)%20
self.hash_table[hash_index] = value
def search(self,value):
hash_index = self.hash(value)
while self.hash_table[hash_index] != value:
hash_index = (hash_index+1)%20
if self.hash_table[hash_index] is None:
print("So such element found")
return
if self.hash_table[hash_index] == value:
print("Element found at index",hash_index)
def delete(self,value):
hash_index = self.hash(value)
while self.hash_table[hash_index] != value:
hash_index = (hash_index+1)%20
if self.hash_table[hash_index] is None:
print("So such element found")
return
if self.hash_table[hash_index] == value:
self.hash_table[hash_index] = None
print("Element deleted")