Ejemplo n.º 1
0
 private static void BubleSort(int[][] mass, ArrayComparerDelegate compDelegate)
 {
     for (int i = 0; i < mass.Length; i++)
     {
         for (int j = i + 1; j < mass.Length; j++)
         {
             if (compDelegate(mass[i], mass[j]) > 0)
             {
                 var temp = mass[i];
                 mass[i] = mass[j];
                 mass[j] = temp;
             }
         }
     }
 }
Ejemplo n.º 2
0
 public void SortTestWithModuleMaxElemArrayComparer_Descending()
 {
     int[][] actual =
     {
         new int[]{2,3,5},
         new int[]{1,2},
         new int[]{4,0,-9,-8}
     };
     int[][] expected =
     {
         new int[]{4,0,-9,-8},
         new int[]{2,3,5},
         new int[]{1,2}
     };
     ModuleMaxElemArrayComparer comparer = new ModuleMaxElemArrayComparer(true);
     ArrayComparerDelegate compDelegate = new ArrayComparerDelegate(comparer.Compare);
     JaggedArraySorts.Sort(actual, compDelegate);
     for (int i = 0; i < actual.Length; i++)
         CollectionAssert.AreEqual(expected[i], actual[i]);
 }
Ejemplo n.º 3
0
 static void Main(string[] args)
 {
     int[][] actual =
     {
         new int[]{2,3,5},
         new int[]{1,2},
         new int[]{4,0,-9,8},
     };
     int[][] expected =
     {
         new int[]{1,2},
         new int[]{2,3,5},
         new int[]{4,0,-9,8},
     };
     MaxLengthArrayComparer comparer = new MaxLengthArrayComparer(true);
     ArrayComparerDelegate compDelegate = new ArrayComparerDelegate(comparer.Compare);
     JaggedArraySorts.Sort(actual, compDelegate);
     PrintArray(expected, "Expected Array");
     PrintArray(actual, "Actual Array");
     Console.ReadKey(true);
 }
Ejemplo n.º 4
0
 public static void Sort(int[][] mass, ArrayComparerDelegate compDelegate)
 {
     if (mass.Length == 0)
         throw new ArgumentNullException("The jagged array to sort is empty");
     BubleSort(mass, compDelegate);
 }