-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprobing.cpp
More file actions
59 lines (47 loc) · 1.23 KB
/
probing.cpp
File metadata and controls
59 lines (47 loc) · 1.23 KB
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
53
54
55
56
57
58
59
#include <vector>
#include "probingnode.cpp"
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
class probing
{
public:
vector<probingnode*>theTable;
probing()
{
theTable.resize(1000);
}
int hashFunction(std::string theString)
{
int sum = 0;
for (int i = 0; i < theString.length(); i++)
{
sum += theString[i];
}
return sum % 1000;
}
void insert(std::string key, int value) {
int hash = hashFunction(key);
while (theTable[hash] != NULL && theTable[hash]->getKey() != key)
hash = (hash + 1) % 300;
if (theTable[hash] != NULL)
delete theTable[hash];
theTable[hash] = new probingnode(key, value);
}
void print()
{
ofstream myfile;
myfile.open ("probingoutput.txt");
for(int i = 0; i < theTable.size(); i++)
{
myfile<< i << "\n";
probingnode* ptr = theTable.at(i);
if (ptr != 0)
{
myfile<< ptr->key<<" ";
}
}
myfile.close();
}
};