fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. //using System.Drawing;
  7.  
  8. namespace LambdaForSort
  9. {
  10.  
  11. struct Point
  12. {
  13. public int X, Y;
  14. public Point(int X, int Y)
  15. {
  16. this.X = X;
  17. this.Y = Y;
  18. }
  19. }
  20.  
  21. class Program
  22. {
  23. static void Main(string[] args)
  24. {
  25. List<Point> Pts = new List<Point>();
  26. Random R = new Random(0);
  27. const int N = 8;
  28.  
  29. Pts.Add(new Point(100, 101));
  30.  
  31. for (int i = 0; i < 16; i++)
  32. {
  33. Pts.Add(new Point(R.Next(N), R.Next(N)));
  34. }
  35. Pts.Add(new Point(100, 99));
  36.  
  37. Console.Write("Orignal:");
  38.  
  39. foreach (Point P in Pts)
  40. {
  41. Console.Write("[{0},{1}] ", P.X, P.Y);
  42. }
  43.  
  44. Console.WriteLine();
  45. Pts.Sort((P1, P2) =>
  46. {
  47. if (P1.X > P2.X) return 1;
  48. if (P1.X < P2.X) return -1;
  49. if (P1.Y > P2.Y) return 1;
  50. if (P1.Y < P2.Y) return -1;
  51. return 0;
  52. });
  53.  
  54. Console.Write("Sorted:");
  55.  
  56. foreach (Point P in Pts)
  57. {
  58. Console.Write("[{0},{1}] ", P.X, P.Y);
  59. }
  60.  
  61. return;
  62. }
  63. }
  64. }
Success #stdin #stdout 0.04s 37040KB
stdin
Standard input is empty
stdout
Orignal:[100,101] [7,2] [7,1] [0,4] [6,5] [6,6] [7,3] [0,5] [2,6] [6,3] [7,3] [2,5] [5,1] [0,1] [6,5] [5,5] [0,0] [100,99] 
Sorted:[0,0] [0,1] [0,4] [0,5] [2,5] [2,6] [5,1] [5,5] [6,3] [6,5] [6,5] [6,6] [7,1] [7,2] [7,3] [7,3] [100,99] [100,101]