Beispiel #1
0
        public static int[] Sort(int[] array)
        {
            int sortedRangeEnd = 0;

            while (sortedRangeEnd < array.Length)
            {
                int nextIndex = FindIndexOfSmallestFromIndex(array, sortedRangeEnd);
                Manipulation <int> .Swap(array, sortedRangeEnd, nextIndex);

                sortedRangeEnd++;
            }

            return(array);
        }
Beispiel #2
0
        public static int[] DescendingSort(int[] array)
        {
            Console.WriteLine("Bubble sorting");

            for (int i = 0; i < array.Length - 1; i++)
            {
                for (int j = 0; j < array.Length - i - 1; j++)
                {
                    if (array[j] > array[j + 1])
                    {
                        Manipulation <int> .Swap(array, j, j + 1);
                    }
                }
            }

            return(array);
        }
Beispiel #3
0
        private static int Partition(int[] array, int left, int right, int pivotIndex)
        {
            int pivotValue = array[pivotIndex];

            Manipulation <int> .Swap(array, pivotIndex, right);

            int storeIndex = left;

            for (int i = left; i < right; i++)
            {
                if (array[i].CompareTo(pivotValue) < 0)
                {
                    Manipulation <int> .Swap(array, i, storeIndex);

                    storeIndex++;
                }
            }

            Manipulation <int> .Swap(array, storeIndex, right);

            return(storeIndex);
        }