コード例 #1
0
        static void Main()
        {
            QuickSortClass quickSortClass = new QuickSortClass();

            /**int[] test = { 25, 36, 14, 3, 87 };
             * //quickSortClass.QuickSort(test, 0, test.Length-1);
             * quickSortClass.MedianQuickSort(test, 0, test.Length - 1);
             * for(int i =0;i<test.Length;i++)
             * {
             *  Console.Write(test[i] + " ");
             * }*/

            string[] files        = { "Input_Random.txt", "Input_ReversedSorted.txt", "Input_Sorted.txt" };
            string[] filesCompare = { "input_100.txt", "input_1000.txt", "input_5000.txt", "input_10000.txt", "input_50000.txt", "input_100000.txt", "input_500000.txt" };

            /** quickSortClass.DriverSrtRstRnd(files);
             * quickSortClass.MedianDriverSrtRstRnd(files);
             * quickSortClass.MedianDriver(filesCompare);
             * quickSortClass.Driver(filesCompare);
             */
            HeapSortClass heapSortClass = new HeapSortClass();

            heapSortClass.Driver(filesCompare);

            Console.ReadKey();
        }
コード例 #2
0
        public void MedianDriverSrtRstRnd(string[] array)
        {
            var timer = new Stopwatch();

            for (int i = 0; i < array.Length; i++)
            {
                HeapSortClass heapSortClass = new HeapSortClass();
                int[]         qs            = heapSortClass.CheckFile(array[i]);
                timer.Start();
                MedianQuickSort(qs, 0, qs.Length - 1);
                timer.Stop();
                Console.WriteLine(timer.Elapsed + " for file " + array[i] + " using Median of 3");
                using (StreamWriter streamWriter = File.AppendText("MedianQuickSortSrtRstRnd.txt"))
                {
                    streamWriter.WriteLine(timer.Elapsed + " for file " + array[i]);
                }
                timer.Reset();
            }
        }
コード例 #3
0
        public void Driver(string[] array)
        {
            var timer = new Stopwatch();

            for (int i = 0; i < array.Length; i++)
            {
                HeapSortClass heapSortClass = new HeapSortClass();
                int[]         qs            = heapSortClass.CheckFile(array[i]);
                timer.Start();
                QuickSort(qs, 0, qs.Length - 1);
                timer.Stop();
                Console.WriteLine(timer.Elapsed + " for size " + qs.Length);
                using (StreamWriter streamWriter = File.AppendText("QuickSort.txt"))
                {
                    streamWriter.WriteLine(timer.Elapsed + " for size " + qs.Length);
                }
                timer.Reset();
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: Vexatori/AlgorithmHW8
        static void Main(string[] args)
        {
            ArrayClass array = new ArrayClass(100000);

            array.SetRandomArray(0, 100);
            //array.ShowArray();

            #region Сортировка пузырьком

            BubbleSortClass.DoSort(ref array);
            //array.ShowArray();
            array.ResetArray();

            Console.WriteLine(
                $"Сортировка пузырьком: {BubbleSortClass.GetTime.ElapsedMilliseconds,5} миллисекунд");

            #endregion

            #region Шейкерная сортировка

            ShakerSortClass.DoSort(ref array);
            //array.ShowArray();
            array.ResetArray();

            Console.WriteLine($"Шейкерная сортировка: {ShakerSortClass.GetTime.ElapsedMilliseconds,5} миллисекунд");

            #endregion

            #region Сортировка вставками

            InsertionSortClass.DoSort(ref array);
            //array.ShowArray();
            array.ResetArray();

            Console.WriteLine($"Сортировка вставками: {InsertionSortClass.GetTime.ElapsedMilliseconds,5} миллисекунд");

            #endregion

            #region Быстрая сортировка

            Stopwatch timer = new Stopwatch();
            timer.Start();
            QuickSortClass.DoSort(ref array, 0, array.Size - 1);
            timer.Stop();
            //array.ShowArray();
            array.ResetArray();

            Console.WriteLine($"Быстрая сортировка: {timer.ElapsedMilliseconds,5} миллисекунд");

            #endregion

            #region Пирамидальная сортировка

            HeapSortClass.DoSort(ref array);
            //array.ShowArray();
            array.ResetArray();

            Console.WriteLine($"Пирамидальная сортировка: {HeapSortClass.GetTime.ElapsedMilliseconds,5} миллисекунд");

            #endregion

            Console.ReadLine();
        }