Example #1
0
 public static void Sort <T>(T[] array) where T : IComparable
 {
     for (int i = 0; i < array.Length - 1; i++)
     {
         int minIndex = i;
         T   minValue = array[i];
         for (int j = i + 1; j < array.Length; j++)
         {
             if (array[j].CompareTo(minValue) < 0)
             {
                 minIndex = j;
                 minValue = array[j];
             }
         }
         SwapHelper.Swap(array, i, minIndex);
     }
 }
Example #2
0
        public static void Sort <T>(T[] array) where T : IComparable
        {
            for (int i = 0; i < array.Length; i++)
            {
                bool swapperd = false;

                for (int j = 0; j < array.Length - 1; j++)
                {
                    if (array[j].CompareTo(array[j + 1]) > 0)
                    {
                        SwapHelper.Swap(array, j, j + 1);
                        swapperd = true;
                    }
                }

                if (!swapperd)
                {
                    break;
                }
            }
        }