-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHash.h
52 lines (41 loc) · 934 Bytes
/
Hash.h
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
41
42
43
44
45
46
47
48
49
50
51
52
#include "LinkedList.h"
#define TBLSize 10 //TBLSize is the size of our Radix. Since for this exampe we are sorting decimal integers, it is 10.
class Hash
{
public:
LinkedList * hash[TBLSize];
Hash()
{
for (int x = 0; x < TBLSize; x++) // Yes, I am doing it like this because I forgot how to do it the other way
{
hash[x] = new LinkedList(); // initializes our Linked Lists
}
}
int hashFunction(int key) //Our key is different from our value and is handled externally (by ptrSort)
{
return key%TBLSize;
}
void Add(int val, int key)
{
int hashVal = hashFunction(key);
hash[hashVal]->Add(val);
}
int getLowest()
{
for (int i = 0; i < TBLSize ; i++)
{
if (hash[i]->Head != nullptr)
{
return hash[i]->deQueue()->value;
}
}
return 0;
}
void printHash() //This is just something that I use for debugging
{
for (int i = 0; i < TBLSize; i++)
{
hash[i]->Print();
}
}
};