Geometric Applications of BSTs
1 1d range search 一维区间搜索
//Returns the number of keys in the symbol table in the given range,两个边界也取进去
public int size(Key lo, Key hi){
if (contains(hi)) return rank(hi) - rank(lo) + 1;
else return rank(hi) - rank(lo);//lo这边的rank始终一样
}
//Does this symbol table contain the given key?
public boolean contains(Key key) {
if (key == null) throw new IllegalArgumentException