堆和BST有什么区别?
何时使用堆以及何时使用BST?
如果你想以排序的方式获取元素,BST是否优于堆?
我想要一张带有重复键的地图.
我知道有很多地图实现(Eclipse向我展示了大约50个),所以我敢打赌必须有一个允许这个.我知道编写自己的地图很容易做到这一点,但我宁愿使用一些现有的解决方案.
也许在commons-collections或google-collections中有什么东西?
我发现方法的java.lang.Integer实现compareTo如下:
public int compareTo(Integer anotherInteger) {
int thisVal = this.value;
int anotherVal = anotherInteger.value;
return (thisVal<anotherVal ? -1 : (thisVal==anotherVal ? 0 : 1));
}
Run Code Online (Sandbox Code Playgroud)
问题是为什么使用比较而不是减法:
return thisVal - anotherVal;
Run Code Online (Sandbox Code Playgroud) java ×3
algorithm ×1
binary-tree ×1
comparison ×1
duplicates ×1
guava ×1
heap ×1
integer ×1
multimap ×1
optimization ×1
overflow ×1