Esempio n. 1
0
        /// <summary>
        /// Rearranges the array in ascending order, using the natural order.
        /// </summary>
        /// <param name="a">a the array to be sorted</param>
        public static void Sort(IComparable[] a, IComparer c = null)
        {
            //make sure we have the comparer passed by argument or create default
            IComparer comparer = c ?? Comparer <object> .Default;

            Knuth.Shuffle(a);

            sort(a, comparer, 0, a.Length - 1);
        }
Esempio n. 2
0
        /// <summary>
        /// Reads in a sequence of strings from standard input, shuffles
        /// them, and prints out the results.
        /// </summary>
        /// <example>Algs4.exe Knuth</example>
        /// <remarks>End of file is CTRL+Z and hit ENTER
        /// if you want to have shuffle of 1 2 3 4 5
        /// type into command line: 1 2 3 4 5
        /// CTRL+Z + hit enter
        /// </remarks>
        /// <param name="args">no parameters expected</param>
        public static void Main(String[] args)
        {
            // read in the data
            String[] a = StdIn.ReadAllStrings();

            //shuffle the array
            Knuth.Shuffle(a);

            // print results.
            for (int i = 0; i < a.Length; i++)
            {
                Console.WriteLine(a[i]);
                Debug.WriteLine(a[i]);
            }
        }