-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHashLista.java
62 lines (54 loc) · 1.54 KB
/
HashLista.java
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
//===================//
//HASH LISTA FLEXIVEL//
//===================//
// METODOS: hash -> add -> search -> remove
package Hashing;
public class HashLista {
final int EMPTY = -1; // flag de index vazio
Lista table[]; // tabela
int t; // tamanho da tabela
// cria a tabela
public HashLista(){
this(13);
}
// PREENCHE a tabela com LISTAS VAZIAS
public HashLista(int t){
this.t = t;
this.table = new Lista[this.t];
for (int i = 0; i < t; i++){
table[i] = new Lista();
}
}
//=====HASH=====//
public int hash(int x){
return x % t;
}
//=====HASH=====//
//=====ADD=====//
public void add(int x){
// se nao existir na tabela
if (!search(x)){
// calcula index com o hash
int id = hash(x);
// convoca metodo da LISTA de ADICIONAR NO INICIO
table[id].addStart(x);
}
}
//=====ADD=====//
//=====SEARCH=====//
public boolean search(int x){
// calcula index com o hash
int id = hash(x);
// convoca metodo da LISTA de PESQUISAR
return table[id].search(x);
}
//=====SEARCH=====//
//=====REMOVE=====//
public void remove(int x){
// calcula index com o hash
int id = hash(x);
// convoca metodo da LISTA de REMOVER
table[id].remove(x);
}
//=====REMOVE=====//
}