Esempio n. 1
0
        static void Main(string[] args)
        {
            int[] array = { 42, 20, 17, 13, 28, 14, 23, 15 };
            //int[] array = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
            AlgorithmHelper.PrintArray(array);

            SortAlgorithm.InsertSort
                (array, ComparerFactory.GetIntComparer());
        }
Esempio n. 2
0
 public static void InsertSort <T, C>(T[] array, C comparer)
     where C : IComparer <T>
 {
     for (int i = 1; i <= array.Length - 1; i++)
     {
         int j = i;
         while (j > 1 && comparer.Compare(array[j], array[i - 1]) < 0)
         {
             swap(ref array[i], ref array[i - 1]);
             j--;
         }
         Console.WriteLine();
         AlgorithmHelper.PrintArray(array);
     }
 }