Skip to content

Add Graham Scan in Java #459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 9, 2018

Conversation

PaddyKe
Copy link
Contributor

@PaddyKe PaddyKe commented Oct 6, 2018

No description provided.

@Gathros Gathros added Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.) Hacktoberfest The label for all Hacktoberfest related things! labels Oct 6, 2018
return 0;
};

hull.sort(angleComparator);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code in this method up to this point could be written as:

        gift = gift
            .stream()
            .distinct()
            .sorted(Comparator.comparingDouble(point -> -point.y))
            .collect(Collectors.toList());

        Point pivot = gift.get(0);

        // Sort the remaining Points based on the angle between the pivot and itself
        List<Point> hull = gift.subList(1, gift.size());
        hull.sort(Comparator.comparingDouble(point -> polarAngle(point, pivot)));

which I think is a bit more readable.

}

public static void main(String[] args) {
ArrayList<Point> points = new ArrayList<Point>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's good practice to not repeat type parameters when it's not necessary:

ArrayList<Point> points = new ArrayList<>();


List<Point> convexHull = grahamScan(points);

convexHull.stream().forEach(p -> System.out.printf("% 1.0f, % 1.0f\n", p.x, p.y));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need the .stream() here, List<T> already has a forEach method.

Copy link
Contributor

@zsparal zsparal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks for incorporating the changes.

@zsparal zsparal merged commit 8b50c0a into algorithm-archivists:master Oct 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Hacktoberfest The label for all Hacktoberfest related things! Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants