Beispiel #1
0
        //Choosing the right Sorting-Algorithm
        public void SortingAlgorithm(SortingAlgorithmEnum sortingAlgorithmEnum)
        {
            SortingAlgorithm sortingAlgorithm = new SortingAlgorithm(this);

            SortingAlgorithm_UpdateMatrixValuesWithView();
            array = CopyDataGridViewXIn1DimensionalMatrix(sortingTable, NullArray(sortingTable));

            switch (sortingAlgorithmEnum)
            {
            case SortingAlgorithmEnum.Qick:
                sortingAlgorithm.QuickSort(CopyDataGridViewXIn1DimensionalMatrix(sortingTable, NullArray(sortingTable)), 0, array.Length - 1);
                break;

            case SortingAlgorithmEnum.Bubble:
                sortingAlgorithm.BubbleSort(CopyDataGridViewXIn1DimensionalMatrix(sortingTable, NullArray(sortingTable)));
                break;

            case SortingAlgorithmEnum.Insertion:
                sortingAlgorithm.InsertionSort(CopyDataGridViewXIn1DimensionalMatrix(sortingTable, NullArray(sortingTable)));
                break;

            case SortingAlgorithmEnum.Selection:
                sortingAlgorithm.SelectionSort(CopyDataGridViewXIn1DimensionalMatrix(sortingTable, NullArray(sortingTable)));
                break;

            case SortingAlgorithmEnum.Shaker:
                sortingAlgorithm.ShakerSort(CopyDataGridViewXIn1DimensionalMatrix(sortingTable, NullArray(sortingTable)));
                break;
            }

            TransferArrayIntoDataGridView(array, sortingTable, NullArray(sortingTable));
            SortingAlgorithm_UpdateViewWithMatrixValues();
        }
        public void BB()
        {
            // 3,4,7,9,12,20,21,22,25
            double[] values = new double[1000];
            Random   random = new Random();

            for (int i = 0; i < values.Length; i++)
            {
                int    num = random.Next(0, 200);
                double dec = random.NextDouble();

                double val = num + dec;
                values[i] = val;
            }

            double[] copy = new double[values.Length];
            values.CopyTo(copy, 0);

            SortingAlgorithm sortingAlgorithm = new SortingAlgorithm();

            sortingAlgorithm.BubbleSort(values);

            copy = copy.OrderBy(x => x).ToArray(); // trusted computing base

            for (int i = 0; i < values.Length; i++)
            {
                Assert.AreEqual(copy[i], values[i]);
            }
        }
Beispiel #3
0
        public void BubbleSort()
        {
            int[] numbersForSorting = { 65, 37, 11, 20, 45, 84, 24, 14, 3 };
            int[] sortedNumbers     = { 3, 11, 14, 20, 24, 37, 45, 65, 84 };
            int[] result            = SortingAlgorithm.BubbleSort(numbersForSorting);

            Assert.Equal(sortedNumbers, result);
        }
Beispiel #4
0
        public static void Sort(this int[] myArray, SortAlgorithm sa)
        {
            System.Console.WriteLine("\nSorting algoritm: ");
            var sortType = new SortingAlgorithm();

            switch (sa)
            {
            case SortAlgorithm.BubbleSort:
                var arr = sortType.BubbleSort(myArray);
                sortType.Traverse(arr);
                break;

            case SortAlgorithm.BogoSort:
                sortType.BogoSort(myArray);
                break;

            case SortAlgorithm.SleepSort:
                sortType.SleepSort(myArray);
                break;

            case SortAlgorithm.SelectionSort:
                sortType.SelectionSort(myArray);
                break;

            case SortAlgorithm.InsertionSort:
                sortType.InsertionSort(myArray);
                break;

            case SortAlgorithm.ShellSort:
                sortType.SelectionSort(myArray);
                break;

            case SortAlgorithm.QuickSort:
                sortType.QuickSort(myArray);
                break;
            }
        }