我在java中创建一个哈希表.在搜索功能中,我在IF语句中进行了一些比较.但它没有做任何比较.
这是我的代码的一部分.
while (table[pos]!=null) {
if (table[pos]==key) {
System.out.println("SEARCH "+key+" at INDEX "+home);
return;
}
else {pos=h(home+p(i));
i++;
}
}
System.out.println("Failed to find "+key+".");
return;
}
Run Code Online (Sandbox Code Playgroud)
即使表[pos]和键是相同的,它也不起作用!但我将非常简单的赋值变量添加到另一个变量.这行得通!我不知道为什么会这样.我想知道它xD
while (table[pos]!=null) {
int x = table[pos];
if (x==key) {
System.out.println("SEARCH "+key+" at INDEX "+home);
return;
}
else {pos=h(home+p(i));
i++;
}
}
System.out.println("Failed to find "+key+".");
return;
}
Run Code Online (Sandbox Code Playgroud)