Exemple #1
0
        public void scenarioOne()
        {
            int[] problemSizes = { 1024, 5120, 25600, 128000 };;
            //integers 1 to N shuffled using the Fisher-Yates algorthm
            for (int i = 0; i < problemSizes.Length; i++)
            {
                int[] array = generateArray(problemSizes[i], false);
                Console.WriteLine("Problem Size " + problemSizes[i] + " : ");
                FisherYatesShuffle fShuffle = new FisherYatesShuffle();
                array = fShuffle.Shuffle(array);
                Stopwatch stopWatch = new Stopwatch();

                //mergeSort testing
                MergeSort <int> mergeS = new MergeSort <int>(array);

                long[] runSpeeds    = new long[100];
                long   runSpeedsSum = 0;
                for (int a = 0; a < runSpeeds.Length; a++)
                {
                    stopWatch.Start();

                    var arraySorted = mergeS.sort();

                    stopWatch.Stop();
                    runSpeeds[i]  = stopWatch.ElapsedTicks;
                    runSpeedsSum += runSpeeds[i];
                }

                //Average
                Console.WriteLine("Merge Sort (Average): " + runSpeedsSum / runSpeeds.Length);
                //heapSort testing
                stopWatch = new Stopwatch();

                //mergeSort testing
                Heap <int> Heap = new Heap <int>(array);
                runSpeeds    = new long[100];
                runSpeedsSum = 0;
                for (int a = 0; a < runSpeeds.Length; a++)
                {
                    stopWatch.Start();
                    var arraySorted = Heap.sortHeap();
                    stopWatch.Stop();
                    runSpeeds[i]  = stopWatch.ElapsedTicks;
                    runSpeedsSum += runSpeeds[i];
                }



                Console.WriteLine("Heap Sort (Average): " + runSpeedsSum / runSpeeds.Length);
                //bucket Sort
                BucketSort <int> bucketSort = new BucketSort <int>(array);
                runSpeeds    = new long[100];
                runSpeedsSum = 0;
                for (int a = 0; a < runSpeeds.Length; a++)
                {
                    stopWatch.Start();
                    var arraySorted = bucketSort.bucketSort();
                    stopWatch.Stop();
                    runSpeeds[i]  = stopWatch.ElapsedTicks;
                    runSpeedsSum += runSpeeds[i];
                }

                Console.WriteLine("Bucket Sort (Average): " + runSpeedsSum / runSpeeds.Length);
            }
        }