示例#1
0
        public static void QuickSort(int[] arrayTest, int startIndex, int endIndex)
        {
            if (startIndex >= endIndex)
            {
                return;
            }
            IndexResult result = Partition(arrayTest, startIndex, endIndex);

            QuickSort(arrayTest, startIndex, result.equalStartIndex - 1);
            QuickSort(arrayTest, result.equalEndIndex + 1, endIndex);
        }
示例#2
0
        public static void RandomQuickSort(int[] arrayTest, int startIndex, int endIndex)
        {
            if (startIndex >= endIndex)
            {
                return;
            }
            int randomIndex = new Random().Next(startIndex, endIndex);

            Exchange(ref arrayTest[randomIndex], ref arrayTest[endIndex]);
            IndexResult result = Partition(arrayTest, startIndex, endIndex);

            RandomQuickSort(arrayTest, startIndex, result.equalStartIndex - 1);
            RandomQuickSort(arrayTest, result.equalEndIndex + 1, endIndex);
        }