我目前正在开发一个项目,并且我被困在这一点上。基本上我想弄清楚如何比较类型:键入类型:Int。从代码中,here.theKey和theKey2是Key类型,Key1以key为参数,获取散列码,然后用于在名为'here'的BST中查找相同的散列码。我遇到的问题是我无法弄清楚如何将this.theKey的值与作为int的key1进行比较。将int值与Java中的不同类型进行比较
这里是方法:
public Value get(Key key)
{
int theKey1 = hash(key);
TreeNode here = Tree;
while (here != null)
{
int theKey2=here.theKey;
if(theKey1 < theKey2)
{
here = here.left;
}
else if(theKey1>theKey2)
here = here.right;
else
{
return here.value;
}
}
throw new IllegalArgumentException("Value associated with the key not found");
}
我试着使用的compareTo但由于theKey1是int类型,我得到了一个错误。任何帮助或指导将不胜感激。
不应该这行'int theKey2 = here.theKey;'是'int theKey2 = hash(here.theKey);'? – Mritunjay
'int theKey2 = hash(here.theKey);',但是究竟是在hashcode上排序的BST的关键点? – EJP
该项目将编写一个程序,该程序使用带链接的Hashtable来处理碰撞,并使用BST代替阵列。 –