-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
40 lines (31 loc) · 786 Bytes
/
main.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
37
38
39
40
### Dictionary ADT
### Implementation hash table implementation
### Count repetitionsx
class DictionaryADT:
def __init__(self):
self.table = [None] * 10
def insert(self, key):
index = self.hash_func(key)
node = self.table[index]
while node:
if node.key == key:
node.value += 1
node = node.next
node = Node(key, 1)
def hash_func(self, key):
return key % 10
def look_up(self, key):
index = self.hash_func(key)
node = self.table[index]
while node:
if node.key == key:
return node
node = node.next
return None
def delete(self, key):
class Node:
def __init__(self, key = None, value = None, next = None):
self.key = key
self.value = value
self.next = next
### WORK IN PROGRESS