Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1. class Point
  2. {
  3.     private int x;
  4.     private int y;
  5.    
  6.     public double getDistanceFromMid()
  7.     {
  8.         Math.Sqrt(Math.Pow(x,2) + Math.Pow(y,2));
  9.     }
  10. }
  11.  
  12.  
  13. class Line
  14. {
  15.     private double m;
  16.     private double n;
  17.     private Node<Point> points;
  18.    
  19.     public void createEmptyList()
  20.     { this.points = null;   }
  21.    
  22.     public void Add(Point p)
  23.     {
  24.         Node<Point> currPoint = this.points;
  25.         while (true)
  26.         {
  27.             if (currPoint == null)
  28.             {
  29.                 currPoint = new Node<Point>(p));
  30.                 break;
  31.             }
  32.             currPoint = currPoint.GetNext();
  33.         }
  34.     }
  35.    
  36.     public Point getClosestToMid()
  37.     {
  38.         Node<Point> currP = this.points;
  39.         double currMaxDistance = 0;
  40.         Point maxPoint = null;
  41.        
  42.         while (currP != null)
  43.         {
  44.             if (currP.GetValue().getDistanceFromMid() > currMaxDistance)
  45.             {
  46.                 currMaxDistance = currP.GetValue().getDistanceFromMid();
  47.                 maxPoint = currP.GetValue();
  48.             }
  49.         }
  50.         return maxPoint;
  51.     }
  52.    
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement