fork(1) download
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. public class MyCustomComparer : IComparer<int>
  5. {
  6. private readonly int _cutOffPointInclusive;
  7.  
  8. public MyCustomComparer(int cutOffPointInclusive)
  9. {
  10. _cutOffPointInclusive = cutOffPointInclusive;
  11. }
  12.  
  13. public int Compare(int x, int y)
  14. {
  15. if (x <= _cutOffPointInclusive || y <= _cutOffPointInclusive)
  16. {
  17. return x.CompareTo(y);
  18. }
  19. else
  20. {
  21. return y.CompareTo(x);
  22. }
  23. }
  24. }
  25.  
  26. public class Test
  27. {
  28. public static void Main()
  29. {
  30. var testData = new List<int>{ 4,7,9,8,20,56,78,34,2,76,84,98 };
  31.  
  32. testData.Sort(new MyCustomComparer(20));
  33.  
  34. foreach (var i in testData)
  35. {
  36. Console.WriteLine(i);
  37. }
  38. }
  39. }
Success #stdin #stdout 0.04s 23968KB
stdin
Standard input is empty
stdout
2
4
7
8
9
20
98
84
78
76
56
34