Beispiel #1
0
        static void Main(string[] args)
        {
            int arraySize = 10000000;

            RandomArray arr = new RandomArray(arraySize);

            arr.FillArrayRandom();

            if (arraySize < 10001)
            {
                Console.WriteLine("Size of the shuffled array :" + arraySize);
                Console.WriteLine("Bubble Sort Took(miliseconds):" + BubbleSort.Sort(arr.Clone()));
                Console.WriteLine("Selection Sort Took(miliseconds):" + SelectionSort.Sort(arr.Clone()));
                Console.WriteLine("Insertion Sort Took(miliseconds):" + InsertionSort.Sort(arr.Clone()));
            }


            Console.WriteLine("Shell Sort Took(miliseconds):" + ShellSort.Sort(arr.Clone()));
            Console.WriteLine("Merge Sort Took(miliseconds):" + MergeSort.Sort(arr.Clone()));
            if (arraySize < 100000)
            {
                Console.WriteLine("Quick Sort Took(miliseconds):" + QuickSort.Sort(arr.Clone()));
            }
            Console.WriteLine("Counting Sort Took(miliseconds):" + CountingSort.Sort(arr.Clone()));
            Console.WriteLine("Radix Sort Took(miliseconds):" + RadixSort.Sort(arr.Clone()));
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            // -------------------- Bubble Sort --------------------
            var bubbleNumbers = new[] { 7, 3, 1, 4, 6, 2, 3 };
            var bubbleSorter  = new BubbleSort();

            bubbleSorter.Sort(bubbleNumbers);
            Console.WriteLine($"[{string.Join(", ", bubbleNumbers)}]");

            // -------------------- Selection Sort --------------------
            var selectionNumbers = new[] { 7, 3, 1, 4, 6, 2, 3 };
            var selectionSorter  = new SelectionSort();

            selectionSorter.Sort(selectionNumbers);
            Console.WriteLine("[{0}]", string.Join(", ", selectionNumbers));

            // -------------------- Insertion Sort --------------------
            var insertionNumbers = new[] { 7, 3, 1, 4, 6, 2, 3 };
            var insertionSorter  = new InsertionSort();

            insertionSorter.Sort(insertionNumbers);
            Console.WriteLine("[{0}]", string.Join(", ", insertionNumbers));

            // -------------------- Merge Sort --------------------
            int[] mergeNumbers = { 7, 3, 1, 4, 6, 2, 3 };
            var   mergeSorter  = new MergeSort();

            mergeSorter.Sort(mergeNumbers);
            Console.WriteLine("[{0}]", string.Join(", ", mergeNumbers));

            // -------------------- Quick Sort --------------------
            int[] quickNumbers = { 7, 3, 1, 4, 6, 2, 3 };
            var   quickSorter  = new QuickSort();

            quickSorter.Sort(quickNumbers);
            Console.WriteLine("[{0}]", string.Join(", ", quickNumbers));

            // -------------------- Counting Sort --------------------
            int[] countingNumbers = { 7, 3, 1, 4, 6, 2, 3 };
            var   countingSorter  = new CountingSort();

            countingSorter.Sort(countingNumbers);
            Console.WriteLine("[{0}]", string.Join(", ", countingNumbers));

            // -------------------- Bucket Sort --------------------
            int[] bucketNumbers = { 7, 3, 1, 4, 6, 2, 3 };
            var   bucketSorter  = new BucketSort();

            bucketSorter.Sort(bucketNumbers, 3);
            Console.WriteLine("[{0}]", string.Join(", ", bucketNumbers));
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            var rnd     = new Random();
            var arrSize = rnd.Next(1, 1000);

            int[] arr = Enumerable.Repeat(0, arrSize).Select(x => rnd.Next(int.MinValue, int.MaxValue)).ToArray();
            var   bs  = (int[])arr.Clone();

            BubbleSort.Sort(bs);
            Assert.IsTrue(IsSorted(bs));

            var ss = (int[])arr.Clone();

            SelectionSort.Sort(ss);
            Assert.IsTrue(IsSorted(ss));

            var @is = (int[])arr.Clone();

            InsertionSort.Sort(@is);
            Assert.IsTrue(IsSorted(@is));

            var ms = (int[])arr.Clone();

            MergeSort.Sort(ms);
            Assert.IsTrue(IsSorted(ms));

            var qs = (int[])arr.Clone();

            QuickSort.Sort(qs);
            Assert.IsTrue(IsSorted(qs));

            var cs = (int[])arr.Clone();

            CountingSort.Sort(cs);
            Assert.IsTrue(IsSorted(cs));

            var rs = (int[])arr.Clone();

            RadixSort.Sort(rs);
            Assert.IsTrue(IsSorted(rs));

            var hs = (int[])arr.Clone();

            HeapSort.Sort(hs);
            Assert.IsTrue(IsSorted(hs));
        }