类 GrahamScan
- java.lang.Object
-
- edu.princeton.cs.algs4.GrahamScan
-
public class GrahamScan extends java.lang.Object
TheGrahamScan
data type provides methods for computing the convex hull of a set of n points in the plane.The implementation uses the Graham-Scan convex hull algorithm. It runs in O(n log n) time in the worst case and uses O(n) extra memory.
For additional documentation, see Section 9.9 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
-
-
构造器概要
构造器 构造器 说明 GrahamScan(Point2D[] points)
Computes the convex hull of the specified array of points.
-
-
-
构造器详细资料
-
GrahamScan
public GrahamScan(Point2D[] points)
Computes the convex hull of the specified array of points.- 参数:
points
- the array of points- 抛出:
java.lang.IllegalArgumentException
- ifpoints
isnull
java.lang.IllegalArgumentException
- if any entry inpoints[]
isnull
java.lang.IllegalArgumentException
- ifpoints.length
is0
-
-
方法详细资料
-
hull
public java.lang.Iterable<Point2D> hull()
Returns the extreme points on the convex hull in counterclockwise order.- 返回:
- the extreme points on the convex hull in counterclockwise order
-
main
public static void main(java.lang.String[] args)
Unit tests theGrahamScan
data type. Reads in an integern
andn
points (specified by their x- and y-coordinates) from standard input; computes their convex hull; and prints out the points on the convex hull to standard output.- 参数:
args
- the command-line arguments
-
-