Пример #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();
        }
Пример #3
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);
        }