Exemple #1
0
        static void Main(string[] args)
        {
            var array = new int[] { 5, 4, 3 };

            Console.WriteLine("Array: " + string.Join(' ', array));

            #region InsertionSort

            var stopWatch = new Stopwatch();
            stopWatch.Start();
            var insertionSortResult = InsertionSort.Sort(array);
            stopWatch.Stop();
            var ts = stopWatch.Elapsed;
            // Format and display the TimeSpan value.
            var elapsedTime = $"{ts.Hours:00}:{ts.Minutes:00}:{ts.Seconds:00}.{ts.Milliseconds / 10:00}";
            Console.WriteLine("Insertion Sort RunTime " + elapsedTime);
            Console.WriteLine("Insertion Sort Result " + string.Join(' ', insertionSortResult));

            #endregion

            #region BubbleSort

            stopWatch = new Stopwatch();
            stopWatch.Start();
            var bubbleSortResult = BubbleSort.Sort(array);
            stopWatch.Stop();
            ts = stopWatch.Elapsed;
            // Format and display the TimeSpan value.
            elapsedTime = $"{ts.Hours:00}:{ts.Minutes:00}:{ts.Seconds:00}.{ts.Milliseconds / 10:00}";
            Console.WriteLine("Bubble Sort RunTime " + elapsedTime);
            Console.WriteLine("Bubble Sort Result " + string.Join(' ', insertionSortResult));

            #endregion

            #region BubbleSort

            stopWatch = new Stopwatch();
            stopWatch.Start();
            var shellSortResult = ShellSort.Sort(array);
            stopWatch.Stop();
            ts = stopWatch.Elapsed;
            // Format and display the TimeSpan value.
            elapsedTime = $"{ts.Hours:00}:{ts.Minutes:00}:{ts.Seconds:00}.{ts.Milliseconds / 10:00}";
            Console.WriteLine("Shell Sort RunTime " + elapsedTime);
            Console.WriteLine("Shell Sort Result " + string.Join(' ', shellSortResult));

            #endregion
        }
Exemple #2
0
        static void Main(string[] args)
        {
            int[] arr = new int[] { 8, 5, 7, 3, 2 };

            #region Bubble Sort
            //var bubbleSort = new BubbleSort();
            //var sortedArray = bubbleSort.Sort(arr);
            //bubbleSort.Print(sortedArray);
            #endregion

            #region Insertion Sort
            //var insertionSort = new InsertionSort();
            //var sortedArray = insertionSort.Sort(arr);
            //insertionSort.Print(sortedArray);
            #endregion

            #region Selection Sort
            //var selectionSort = new SelectionSort();
            //var sortedArray = selectionSort.Sort(arr);
            //selectionSort.Print(sortedArray);
            #endregion

            #region Quick Sort
            //int[] arr2 = new int[] { 11, 13, 7, 12, 16, 9, 24, 5, 10, 3, int.MaxValue };
            #endregion

            #region Merge Sort
            //int[] arr2 = new int[] { 8, 3, 7, 4, 9, 2, 6, 5 };
            //var mergeSort = new MergeSort();
            //var sortedArray = mergeSort.Sort(arr2);
            //mergeSort.Print(sortedArray);
            #endregion

            #region Count Sort
            //int[] arr2 = new int[] { 6, 3, 9, 10, 15, 6, 8, 12, 3, 6 };
            //var countSort = new CountSort();
            //var sortedArray = countSort.Sort(arr2);
            //countSort.Print(sortedArray);
            #endregion

            #region Bin/Bucket Sort
            //int[] arr2 = new int[] { 6, 3, 9, 10, 15, 6, 8, 12, 3, 6 };
            //var binSort = new BinSort();
            //var sortedArray = binSort.Sort(arr2);
            //binSort.Print(sortedArray);
            #endregion

            #region Radix Sort
            //int[] arr2 = new int[] { 237, 146, 259, 348, 152, 163, 235, 48, 36, 62 };
            //var radixSort = new RadixSort();
            //var sortedArray = radixSort.Sort(arr2);
            //radixSort.Print(sortedArray);
            #endregion

            #region Shell Sort
            int[] arr2        = new int[] { 9, 5, 16, 8, 13, 6, 12, 10, 4, 2, 3 };
            var   shellSort   = new ShellSort();
            var   sortedArray = shellSort.Sort(arr2);
            shellSort.Print(sortedArray);
            #endregion
        }