예제 #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();
        }
예제 #2
0
        public static void Test()
        {
            int[] arr = { 170, 45, 75, 90, 802, 24, 2, 66 };
            int   n   = arr.Length;

            RadixSort.Sort(ref arr, n);
            Console.ReadLine();
        }
        private static int[] RunRadixSort(int arraySize, int[] bigArray)
        {
            var watch = System.Diagnostics.Stopwatch.StartNew();
            var bs    = RadixSort.SortInt((int[])bigArray.Clone());

            watch.Stop();
            Console.WriteLine($"RadixSort {arraySize} elements = {watch.ElapsedMilliseconds} ms");

            return(bs);
        }
예제 #4
0
        static void Main(string[] args)
        {
            //SolveWithCountingSort();
            //SolveWithInsertionSort();
            string test = "170 45 75 90 802 24 2 66"; //"0 0 2 9 4 5 2 4 9 8 3 1 0";

            int[] testCase = GetTest(test, 8);
            Display(testCase);

            // replace the sort here with other sort algorithms
            ISort sort = new RadixSort();

            int[] result = sort.Sort(testCase);
            Display(result);
        }
예제 #5
0
        /* By: John O'Brien, James Doggett
         * Date: 4/21/2018
         * Last Updated: 4/23/2018
         *
         * This project is designed to test several different sort implementations to check for the
         * highest performing sort under three conditions: Randomly filled array, Ascending order array,
         * and Descending order array.
         */
        static void Main(string[] args)
        {
            //From Stopwatch to right sw.Reset, except for the PrintRandom, is currently here just to
            //test the RadixSort.  This can be deleted and PrintRandom uncommented to see all three
            //sorts run at once.
            Stopwatch sw = new Stopwatch();

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

            //PrintRandom();    //uncomment this line to run all three sorts
            myArray = RandArray();
            sw.Start();
            RadixSort.RSort(myArray);
            sw.Stop();
            timer = sw.ElapsedMilliseconds.ToString();
            Console.WriteLine("Elapsed time, RadixSort: {0}", timer);
            sw.Reset();
            //RadixSort.PrintArray(myArray);
            //QuickSort.PrintArray(myArray);
            Console.WriteLine("Random array times.");
            Console.ReadKey();
        }