Exemplo n.º 1
0
        static void Main(string[] args)
        {
            int[]             sortArray      = { 30, 40, 10, 87, 90, 5, 25, 67, 100, 3, 15 };
            SortingAlgorithms sortArrayClass = new SortingAlgorithms();

            Console.WriteLine("Array without Sorting:");
            sortArrayClass.printArray(sortArray);
            Console.WriteLine();

            Console.WriteLine("Bubble Sort:");
            sortArrayClass = new BubbleSort();
            sortArrayClass.bubbleSort(sortArray);
            sortArrayClass.printArray(sortArray);
            Console.WriteLine();

            Console.WriteLine("Selection Sort:");
            int[] SelectionsortArray = { 30, 40, 10, 87, 90, 5, 25, 67, 100, 3, 15 };
            sortArrayClass = new SelectionSort();
            sortArrayClass.selectionSort(SelectionsortArray);
            sortArrayClass.printArray(SelectionsortArray);
            Console.WriteLine();

            Console.WriteLine("Merge Sort:");
            int[] MergesortArray = { 30, 40, 10, 87, 90, 5, 25, 67, 100, 3, 15 };
            sortArrayClass = new MergeSort();
            sortArrayClass.mergeSort(MergesortArray, 0, MergesortArray.Length - 1);
            sortArrayClass.printArray(MergesortArray);
            Console.WriteLine();


            Console.WriteLine("Insertion Sort:");
            int[] InsertionArray = { 30, 40, 10, 87, 90, 5, 25, 67, 100, 3, 15 };
            sortArrayClass = new InsertionSort();
            sortArrayClass.insertionSort(InsertionArray);
            sortArrayClass.printArray(InsertionArray);
            Console.WriteLine();



            Console.WriteLine("Quick Sort:");
            int[] QuickArray = { 30, 40, 10, 87, 90, 5, 25, 67, 100, 3, 15 };
            sortArrayClass = new QuickSort();
            sortArrayClass.quickSort(QuickArray, 0, QuickArray.Length - 1);
            sortArrayClass.printArray(QuickArray);
            Console.WriteLine();


            Console.WriteLine("Heap Sort:");
            int[] HeapArray = { 30, 40, 10, 87, 90, 5, 25, 67, 100, 3, 15 };
            sortArrayClass = new HeapSort();
            sortArrayClass.heapSort(HeapArray);
            sortArrayClass.printArray(HeapArray);
            Console.WriteLine();

            Console.ReadLine();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            int size  = 20000;
            int range = 10000;

            BubbleSort bubbleSort = new BubbleSort();

            int[] unsortedArray1 = Utils.generateArray(size, range);

            var watch = System.Diagnostics.Stopwatch.StartNew();

            bubbleSort.bubbleSort(unsortedArray1);
            watch.Stop();
            var elapsedMs = watch.Elapsed.TotalMilliseconds;

            Console.WriteLine("bubble took time: " + elapsedMs);

            CountSort countSort = new CountSort();

            int[] unsortedArray2 = Utils.generateArray(size, range);

            watch = System.Diagnostics.Stopwatch.StartNew();
            countSort.countSort(unsortedArray2);
            watch.Stop();
            elapsedMs = watch.Elapsed.TotalMilliseconds;

            Console.WriteLine("count took time: " + elapsedMs);

            MergeSort mergeSort = new MergeSort();

            int[] unsortedArray3 = Utils.generateArray(size, range);

            watch = System.Diagnostics.Stopwatch.StartNew();
            MergeSort.sort(unsortedArray3, 0, unsortedArray3.Length - 1);
            watch.Stop();
            elapsedMs = watch.Elapsed.TotalMilliseconds;

            Console.WriteLine("merge took time: " + elapsedMs);

            InsertionSort insertionSort = new InsertionSort();

            int[] unsortedArray4 = Utils.generateArray(size, range);

            watch = System.Diagnostics.Stopwatch.StartNew();
            insertionSort.insertionSort(unsortedArray4);
            watch.Stop();
            elapsedMs = watch.Elapsed.TotalMilliseconds;

            Console.WriteLine("insertion took time: " + elapsedMs);

            QuickSort quickSort = new QuickSort();

            int[] unsortedArray5 = Utils.generateArray(size, range);

            watch = System.Diagnostics.Stopwatch.StartNew();
            quickSort.quickSort(unsortedArray5);
            watch.Stop();
            elapsedMs = watch.Elapsed.TotalMilliseconds;

            Console.WriteLine("quick took time: " + elapsedMs);


            HeapSort heapSort = new HeapSort();

            int[] unsortedArray6 = Utils.generateArray(size, range);

            watch = System.Diagnostics.Stopwatch.StartNew();
            heapSort.heapSort(unsortedArray6);
            watch.Stop();
            elapsedMs = watch.Elapsed.TotalMilliseconds;

            Console.WriteLine("heap took time: " + elapsedMs);

            SelectionSort selectionSort = new SelectionSort();

            int[] unsortedArray7 = Utils.generateArray(size, range);

            watch = System.Diagnostics.Stopwatch.StartNew();
            selectionSort.selectionSort(unsortedArray7);
            watch.Stop();
            elapsedMs = watch.Elapsed.TotalMilliseconds;

            Console.WriteLine("selection took time: " + elapsedMs);

            Console.ReadKey();
        }