Exemple #1
0
        /*
         * This module was present in the main body of the project, it was moved to this module to
         * facilitate testing a single sort at a time without having to delete or comment out parts.
         * It creates a new random array before it runs each sort, so they are not run on identical arrays.         *
         */
        public static void PrintRandom()
        {
            //initialize our array and our common variables
            Stopwatch sw = new Stopwatch();

            int[]  myArray = RandArray();
            string timer;

            sw.Start();
            QuickSort.QSort(myArray, 0, myArray.Length - 1);
            sw.Stop();
            timer = sw.ElapsedMilliseconds.ToString();
            Console.WriteLine("Elapsed time, Quicksort: {0}", timer);
            sw.Reset();
            //Generate a new array for Radix sort
            myArray = RandArray();
            sw.Start();
            RadixSort.RSort(myArray);
            sw.Stop();
            timer = sw.ElapsedMilliseconds.ToString();
            Console.WriteLine("Elapsed time, RadixSort: {0}", timer);
            sw.Reset();
            //Generate a new array for the sample Radix sort
            myArray = RandArray();
            sw.Start();
            RadixSort.Sort(myArray);
            sw.Stop();
            timer = sw.ElapsedMilliseconds.ToString();
            Console.WriteLine("Elapsed time, Rosetta Code Radix Sort: {0}", timer);
            sw.Reset();
        }