-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtabellahash.cpp
More file actions
59 lines (46 loc) · 1.09 KB
/
tabellahash.cpp
File metadata and controls
59 lines (46 loc) · 1.09 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 "tabellahash.h"
TabellaHash::TabellaHash(int lunghezza)
{ if (lunghezza == 0) size_table=5;
else size_table = lunghezza;
hashtable.resize(size_table);
cout<<"Il tuo dizionario e' pronto!"<<endl;
}
int TabellaHash::hash(string s)
{
char *temp= (char *)s.c_str();
int h=0, a = 127;
for(; *temp !=0; temp++)
h= (a *h + *temp) %size_table;
return h;
}
bool TabellaHash::inserimento(PAROLE par)
{
int posizione=hash(par.getP());
if( hashtable.at(posizione).inserisci(par) == true)
return true;
else return false;
}
void TabellaHash::rimozione(string par)
{
int posizione=hash(par);
hashtable.at(posizione).rimuovi(par);
}
bool TabellaHash::ricerca(string par)
{
int posizione=hash(par);
if ( hashtable.at(posizione).cerca(par) == false ) {return false;}
else return true;
}
void TabellaHash::stampaT()
{
cout<<"Dizionario :"<<endl<<endl;
for(int i=0;i<size_table;i++)
{
hashtable.at(i).stampa();
}
cout<<endl;
}
int TabellaHash::size()
{return size_table;}
TabellaHash::~TabellaHash()
{}