예제 #1
0
        private static void Improved2Sort(T[] xs, int lo, int hi)
        {
            if (hi <= lo + M)
            {
                Insertion <T> .Sort(xs, lo, hi);

                return;
            }

            int lt = lo;
            int gt = hi;
            int i  = lo + 1;
            T   v  = xs[lo];

            while (i <= gt)
            {
                int cmp = xs[i].CompareTo(v);
                if (cmp < 0)
                {
                    Sorting <T> .Exchange(xs, lt ++, i ++);
                }
                else if (cmp > 0)
                {
                    Sorting <T> .Exchange(xs, i, gt --);
                }
                else
                {
                    i++;
                }
            } // Now xs[lo..lt-1] < v = xs[lt..gt] < xs[gt+1..hi]

            Improved2Sort(xs, lo, lt - 1);
            Improved2Sort(xs, gt + 1, hi);
        }
예제 #2
0
        private static void Improved1Sort(T[] xs, int lo, int hi)
        {
            if (hi <= lo + M)
            {
                Insertion <T> .Sort(xs, lo, hi);

                return;
            }
            int j = Partition(xs, lo, hi);

            Improved1Sort(xs, lo, j - 1);
            Improved1Sort(xs, j + 1, hi);
        }