Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Point
- {
- private int x;
- private int y;
- public double getDistanceFromMid()
- {
- Math.Sqrt(Math.Pow(x,2) + Math.Pow(y,2));
- }
- }
- class Line
- {
- private double m;
- private double n;
- private Node<Point> points;
- public void createEmptyList()
- { this.points = null; }
- public void Add(Point p)
- {
- Node<Point> currPoint = this.points;
- while (true)
- {
- if (currPoint == null)
- {
- currPoint = new Node<Point>(p));
- break;
- }
- currPoint = currPoint.GetNext();
- }
- }
- public Point getClosestToMid()
- {
- Node<Point> currP = this.points;
- double currMaxDistance = 0;
- Point maxPoint = null;
- while (currP != null)
- {
- if (currP.GetValue().getDistanceFromMid() > currMaxDistance)
- {
- currMaxDistance = currP.GetValue().getDistanceFromMid();
- maxPoint = currP.GetValue();
- }
- }
- return maxPoint;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement