Пример #1
0
 public static List <int> Sort(int[] input)
 {
     if (input == null || input.Length < 2)
     {
         return(input.ToList());
     }
     (int[] h1, int[] h2) = AlgorithmHelpers.SplitInHalf(input.ToArray());
     return(Merge(Sort(h1).ToArray(), Sort(h2).ToArray()));
 }
Пример #2
0
 public static (List <int> Items, int Inversions) MergeSortInversions(IEnumerable <int> input)
 {
     if (input == null || input.Count() < 2)
     {
         return(input.ToList(), 0);
     }
     (int[] a, int[] b)           = AlgorithmHelpers.SplitInHalf(input.ToArray());
     (List <int> sortedA, int ai) = MergeSortInversions(a);
     (List <int> sortedB, int bi) = MergeSortInversions(b);
     return(Merge(sortedA.ToArray(), sortedB.ToArray(), ai + bi));
 }