Skip to content

Instantly share code, notes, and snippets.

@eyalcohen4
Created June 21, 2017 10:38
Show Gist options
  • Save eyalcohen4/3974494cc5516010daf55d2eff104d6e to your computer and use it in GitHub Desktop.
Save eyalcohen4/3974494cc5516010daf55d2eff104d6e to your computer and use it in GitHub Desktop.
public double calcPerimeter() {
double peri = 0;
if (head.getNext() == null) {
return peri;
} else if (head.getNext().getNext() == null) {
return head.getPoint().distance(head.getNext().getPoint());
}
PointNode iterable = head;
while (iterable.getNext().getNext() != null) {
if (iterable.getNext() == null) {
peri += iterable.getPoint().distance(head.getPoint());
} else {
peri += iterable.getPoint().distance(iterable.getNext().getPoint());
iterable = iterable.getNext();
}
}
return peri;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment