我的任务使用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)。 –