Example #1
0
        /// <summary>
        /// Rearranges the array in ascending order, using the natural order.
        /// </summary>
        /// <param name="carr">the array to be sorted</param>
        public static void Sort(IComparable[] carr)
        {
            int num = carr.Length;

            for (int i = 0; i < num; i++)
            {
                int num2 = i;
                while (num2 > 0 && Insertion.less(carr[num2], carr[num2 - 1]))
                {
                    Insertion.exch(carr, num2, num2 - 1);
                    num2 += -1;
                }

                Debug.Assert(Insertion.isSorted(carr, 0, i));
            }

            Debug.Assert(Insertion.isSorted(carr));
        }
Example #2
0
        /// <summary>
        /// Rearranges the array in ascending order, using a comparator.
        /// </summary>
        /// <param name="objarr">the array</param>
        /// <param name="c">comparator the comparator specifying the order, Java type is <see cref="Comparator"/></param>
        public static void Sort(object[] objarr, IComparer c)
        {
            int num = objarr.Length;

            for (int i = 0; i < num; i++)
            {
                int num2 = i;
                while (num2 > 0 && Insertion.less(c, objarr[num2], objarr[num2 - 1]))
                {
                    Insertion.exch(objarr, num2, num2 - 1);
                    num2 += -1;
                }

                Debug.Assert(Insertion.isSorted(objarr, c, 0, i));
            }

            Debug.Assert(Insertion.isSorted(objarr, c));
        }
Example #3
0
 private static bool isSorted(object[] array, IComparer comparator)
 {
     return(Insertion.isSorted(array, comparator, 0, array.Length - 1));
 }
Example #4
0
 private static bool isSorted(IComparable[] array)
 {
     return(Insertion.isSorted(array, 0, array.Length - 1));
 }