Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace NewLesson1
- {
- class Program
- {
- struct Point
- {
- public int x;
- public int y;
- public Point(int x, int y)
- {
- this.x = x;
- this.y = y;
- }
- public override string ToString()
- {
- return $"{x} {y}";
- }
- public static void sort(Point[] points)
- {
- Point b;
- for (int j = 0; j < points.Length - 1; ++j)
- {
- for (int i = 1; i < points.Length; ++i)
- {
- if (points[i].Equals( points[i] + points[i - 1])){
- b = points[i - 1];
- points[i - 1] = points[i];
- points[i] = b;
- }
- }
- }
- }
- public static Point operator+(Point left, Point right) //Определяю наибольший из пары Pointов. Перегрузил +, так как с < и > нужно перегружать оба знака обязательно.
- {
- if (left.x == right.x)
- {
- if (left.y > right.y) return new Point(left.x, left.y);
- else return new Point(right.x, right.y);
- }
- else
- {
- if (left.x > right.x) return new Point(left.x, left.y);
- else return new Point(right.x, right.y);
- }
- }
- }
- static void Main(string[] args)
- {
- Point[] points = new Point[3];
- points[0] = new Point(2, 4);
- points[1] = new Point(2, 8);
- points[2] = new Point(3, 2);
- Point.sort(points);
- for (int i = 0; i < points.Length; ++i)
- {
- Console.WriteLine(points[i]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement