我不是很有经验,正在尝试处理我的哈希表中的冲突。但是,它只是跳过它,根本不写它。我认为带有条件 if 的 while 循环会处理它......我已经玩了一段时间了,感觉就像我把所有东西都搞混了或者失去了理智。
File file = new File("info.txt");
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
String line;
while ((line = br.readLine()) != null) {
temp = nhash.hashing(line,maxSize);
System.out.println(line + " " + " Hash key: " + temp);
int loc = (int)temp;
if(arr[loc] != null) // I FIGURED THIS WOULD SOLVE it
{ // THE ISSUE... But IT DOESN'T
while(arr[loc] != null) {
// System.out.println("Collision at [" + loc + "] with Data Item : [" + arr[loc] + "]");
loc++;
if(loc == maxSize)
loc = 0;
}
}else {
arr[loc] = line;
// System.out.println("Data Item[" + line + "] Stored in index [" + loc + "] of array.");
key[j] = loc;
j++;
}
}