Esempio n. 1
0
 public T[] Sort <T>(T[] input) where T : IComparable
 {
     for (int i = 0; i < input.Length - 1; i++)
     {
         int jMin = i;
         for (int j = i + 1; j < input.Length; j++)
         {
             if (input[j].CompareTo(input[jMin]) < 0)
             {
                 jMin = j;
             }
         }
         SortingUtils.Swap(input, i, jMin);
     }
     return(input);
 }
Esempio n. 2
0
        private int Partition <T>(T[] input, int low, int high) where T : IComparable
        {
            T   pivot = input[high];
            int i     = low;

            for (int j = low; j < high; j++)
            {
                if (input[j].CompareTo(pivot) < 0)
                {
                    SortingUtils.Swap(input, i, j);
                    i++;
                }
            }
            SortingUtils.Swap(input, i, high);
            return(i);
        }