-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashTable.cpp
More file actions
72 lines (56 loc) · 1.4 KB
/
Copy pathHashTable.cpp
File metadata and controls
72 lines (56 loc) · 1.4 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
60
61
62
63
64
65
66
67
68
69
70
71
72
// Implementation file for the Hash class
// Written By: A. Student
// Changed by: Tauhid Malik
#include <string>
#include "HashTable.h"
using namespace std;
/*~*~*~*
A simple hash function
*~**/
int HashTable::_hash(string key) const
{
int sum = 0;
for (int i = 0; key[i]; i++)
sum += key[i];
return sum % hashSize;
};
/*~*~*~*
hash insert - linear probe
*~**/
bool HashTable::insert(const Student &itemIn)
{
if (count == hashSize)
return false;
int hashIndex = _hash(itemIn.getName());
for (int i = 0; i < hashSize; i++) {
int index = (hashIndex + i) % hashSize;
if (!(hashAry[index].getOccupied())) {
hashAry[index].setItem(itemIn);
hashAry[index].setOccupied(1);
break;
}
hashAry[index].setNoCollisions(hashAry[index].getNoCollisions() + 1);
}
return true;
}
/*~*~*~*
hash delete - linear probe
*~**/
bool HashTable::remove(Student &itemOut)
{
return false;
}
/*~*~*~*
hash search - linear probe
search for key
if found:
- copy data to itemOut
- copy number of collisions for this key to noCol
- returns true
if not found, returns false
*~**/
bool HashTable::search(Student &itemOut, int &noCol, string key)
{
/* write your code here */
return false;
}