-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHashPlayer.h
73 lines (56 loc) · 1.15 KB
/
HashPlayer.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#pragma once
#include <iostream>
#include "singlyLinkedList.h"
#include "teamLinkedList.h"
#include "TeamBST.h"
#include "Source.h"
#include <cstring>
#include "Assists.h"
// Hashtable to implement the players and their assists
using namespace std;
class hashtable_player
{
public:
Assist** hasharray = new Assist* [1000]{NULL};
void insert(Assist* newassist)
{
int location = hashfunction(newassist->player_name);
if (hasharray[location] == NULL)
{
hasharray[location] = newassist;
}
else
{
Assist* loc = hasharray[location];
Assist* ploc = NULL;
while (loc != NULL)
{
ploc = loc;
loc = loc->next;
}
ploc->next = newassist;
}
}
Assist* search(string player_name)
{
int location = hashfunction(player_name);
Assist* loc = hasharray[location];
Assist* ploc = NULL;
while (loc != NULL && loc->player_name != player_name)
{
ploc = loc;
loc = loc->next;;
}
return loc;
}
int hashfunction(string player_name)
{
long long int hash = 0;
hash = 3;
for (int i = 0; i < player_name.length(); i++)
{
hash = hash + 7 * (int)player_name[i];
}
return hash % 1000;
}
};