我的任務使用java.util.TreeSet
使用二叉查找樹實現點集API類。所述點集API概況如下所示:使用二叉搜索樹實現一組點
public class PointSET {
public PointSET() {} // construct an empty set of points
public boolean isEmpty() {} // is the set empty?
public int size() {} // number of points in the set
public void insert(Point2D p) {} // add the point p to the set (if it is not already in the set)
public boolean contains(Point2D p) {} // does the set contain the point p?
public Collection<Point2D> range(RectHV rect) {} // all points in the set that are inside the rectangle
public Point2D nearest(Point2D p) {} // a nearest neighbor in the set to p; null if set is empty
}
- 的
Point2
對象是一個簡單的點,其中x和y座標以及一些其他方法的兩個點之間的計算距離。 RectHV
對象表示在矩形內的點的範圍搜索中使用的矩形。
我想我不確定如何在BST中實現這個API類。我們已經在課堂上了解了BST的知識,但只是從廣義上講;它們是什麼以及後序/前序/中序的搜索方式。
我也很困惑API是什麼和它本身。是什麼讓這個API成爲一種API而不是而不是?
「實施」API涉及什麼?以及如何使用java.util.TreeSet
來做到這一點?
我將不勝感激任何幫助。
您將使用BST作爲數據結構來存儲所有點,而不是將它們存儲在另一個結構中,例如數組 – AlexBrand
'TreeSet' *是一個二叉查找樹;在內部它被實現爲紅黑樹。所以'TreeSet'如何與實現自己的BST連接並不是很清楚,但有關如何使用'TreeSet'的詳細信息,請參閱[它的文檔](http://docs.oracle.com/javase/7/docs/ API/JAVA/util的/ TreeSet.html)。 –