-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashTableString
More file actions
36 lines (29 loc) · 904 Bytes
/
HashTableString
File metadata and controls
36 lines (29 loc) · 904 Bytes
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
package bangbam;
import java.util.LinkedList;
import java.util.Scanner;
public class MangBamString {
//Kích thước của độ dài mảng băm tùy theo đề bài ra
final int tableSize = 113;
LinkedList<Integer>[]lists = new LinkedList[tableSize];
void defineHashTable(){
//Mảng danh sách liên k
for (int i = 0;i<tableSize;i++){
lists[i] = new LinkedList();
}
}
int hfst(String t){
int s = 0;
for (int i = 0;i<t.length();i++)
s +=(int)t.charAt(i);
return s% tablesize;
}
void insert(String x){
int pos = hfs(x);
//Kiểm tra xem đã có x hay chưa, nếu chưa có thì add vào
if (!lists[pos].contains(x))
lists[pos].add(x);
}
public static void main(String[] args) {
MangBamInteger s = new MangBamInteger();
}
}