Exemple #1
0
        public static void MainTest(string[] args)
        {
            TextInput StdIn = new TextInput();

            string[] a = StdIn.ReadAllStrings();
            Insertion.Sort(a);
            OrderHelper.Show(a);
        }
Exemple #2
0
        private static void Sort(IComparable[] src, IComparable[] dst, int lo, int hi)
        {
            // if (hi <= lo) return;
            if (hi <= lo + CUTOFF)
            {
                Insertion.Sort(dst, lo, hi);
                return;
            }
            int mid = lo + (hi - lo) / 2;

            Sort(dst, src, lo, mid);
            Sort(dst, src, mid + 1, hi);

            if (!OrderHelper.Less(src[mid + 1], src[mid]))
            {
                Array.Copy(src, lo, dst, lo, hi - lo + 1);
                return;
            }
            Merge(src, dst, lo, mid, hi);
        }
Exemple #3
0
        private static void Sort <T>(T[] src, T[] dst, int lo, int hi, Comparer <T> comparator)
        {
            // if (hi <= lo) return;
            if (hi <= lo + CUTOFF)
            {
                Insertion.Sort(dst, lo, hi, comparator);
                return;
            }
            int mid = lo + (hi - lo) / 2;

            Sort(dst, src, lo, mid, comparator);
            Sort(dst, src, mid + 1, hi, comparator);

            if (!OrderHelper.Less(src[mid + 1], src[mid], comparator))
            {
                Array.Copy(src, lo, dst, lo, hi - lo + 1);
                return;
            }

            Merge(src, dst, lo, mid, hi, comparator);
        }