Пример #1
0
        private void createStringArray()
        {
            _stringArray = new string[_arraySize];
            string s;

            if (_minStringLength != _maxStringLength)
            {
                for (uint i = 0; i < _arraySize; i++)
                {
                    s = "";
                    for (short j = 0; j < rnd.Next(_minStringLength, _maxStringLength + 1); j++)
                    {
                        s += (char)(rnd.Next(97, 123));
                    }
                    _stringArray[i] = s;
                }
            }
            else
            {
                for (uint i = 0; i < _arraySize; i++)
                {
                    s = "";
                    for (short j = 0; j < _minStringLength; j++)
                    {
                        s += (char)(rnd.Next(97, 123));
                    }
                    _stringArray[i] = s;
                }
            }

            if (arrayInitialOrderComboBox.SelectedIndex != 0)
            {
                SortAlgs.HeapSort(_stringArray, (arrayInitialOrderComboBox.SelectedIndex == 1) ? true : false);
            }
        }
Пример #2
0
        private void createInt64Array()
        {
            _Int64Array = new long[_arraySize];

            for (uint i = 0; i < _arraySize; i++)
            {
                _Int64Array[i] = (long)(long.MinValue + (rnd.NextDouble() * (ulong.MaxValue)));
            }

            if (arrayInitialOrderComboBox.SelectedIndex != 0)
            {
                SortAlgs.HeapSort(_Int64Array, (arrayInitialOrderComboBox.SelectedIndex == 1) ? true : false);
            }
        }
Пример #3
0
        private void createInt32Array()
        {
            _Int32Array = new int[_arraySize];

            for (uint i = 0; i < _arraySize; i++)
            {
                _Int32Array[i] = rnd.Next(int.MinValue, int.MaxValue);
            }

            if (arrayInitialOrderComboBox.SelectedIndex != 0)
            {
                SortAlgs.HeapSort(_Int32Array, (arrayInitialOrderComboBox.SelectedIndex == 1) ? true : false);
            }
        }
Пример #4
0
        private void createByteArray()
        {
            _byteArray = new byte[_arraySize];

            for (uint i = 0; i < _arraySize; i++)
            {
                _byteArray[i] = (byte)rnd.Next(byte.MinValue, byte.MaxValue + 1);
            }

            if (arrayInitialOrderComboBox.SelectedIndex != 0)
            {
                SortAlgs.HeapSort(_byteArray, (arrayInitialOrderComboBox.SelectedIndex == 1) ? true : false);
            }
        }
Пример #5
0
        private void PerformSort()
        {
            switch (arrayTypesComboBox.SelectedIndex)
            {
            case 0:
                switch ((SortAlgsEnum)sortAlgComboBox.SelectedIndex)
                {
                case SortAlgsEnum.BUBBLE_SORT:
                    SortAlgs.BubbleSort(_sortedByteArray, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                case SortAlgsEnum.INSERTION_SORT:
                    SortAlgs.InsertionSort(_sortedByteArray, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                case SortAlgsEnum.QUICK_SORT:
                    SortAlgs.QuickSort(_sortedByteArray, 0, _sortedByteArray.Length - 1, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                case SortAlgsEnum.MERGE_SORT:
                    SortAlgs.MergeSort(_sortedByteArray, 0, _sortedByteArray.Length - 1, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                case SortAlgsEnum.HEAP_SORT:
                    SortAlgs.HeapSort(_sortedByteArray, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                case SortAlgsEnum.PIGEON_SORT:
                    SortAlgs.PigeonholeSort(_sortedByteArray, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                case SortAlgsEnum.COUNT_SORT:
                    SortAlgs.CountingSort(_sortedByteArray, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                case SortAlgsEnum.RADIX_SORT:
                    SortAlgs.RadixSort(_sortedByteArray, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                case SortAlgsEnum.SHELL_SORT:
                    SortAlgs.ShellSort(_sortedByteArray, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                case SortAlgsEnum.BINARY_INSERTION_SORT:
                    SortAlgs.BinaryInsertionSort(_sortedByteArray, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                default:
                    break;
                }
                break;

            case 1:
                switch ((SortAlgsEnum)sortAlgComboBox.SelectedIndex)
                {
                case SortAlgsEnum.BUBBLE_SORT:
                    SortAlgs.BubbleSort(_sortedInt16Array, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                case SortAlgsEnum.INSERTION_SORT:
                    SortAlgs.InsertionSort(_sortedInt16Array, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                case SortAlgsEnum.QUICK_SORT:
                    SortAlgs.QuickSort(_sortedInt16Array, 0, _sortedInt16Array.Length - 1, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                case SortAlgsEnum.MERGE_SORT:
                    SortAlgs.MergeSort(_sortedInt16Array, 0, _sortedInt16Array.Length - 1, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                case SortAlgsEnum.HEAP_SORT:
                    SortAlgs.HeapSort(_sortedInt16Array, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                case SortAlgsEnum.PIGEON_SORT:
                    SortAlgs.PigeonholeSort(_sortedInt16Array, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                case SortAlgsEnum.COUNT_SORT:
                    SortAlgs.CountingSort(_sortedInt16Array, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                case SortAlgsEnum.RADIX_SORT:
                    SortAlgs.RadixSort(_sortedInt16Array, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                case SortAlgsEnum.SHELL_SORT:
                    SortAlgs.ShellSort(_sortedInt16Array, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                case SortAlgsEnum.BINARY_INSERTION_SORT:
                    SortAlgs.BinaryInsertionSort(_sortedInt16Array, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                default:
                    break;
                }
                break;

            case 2:
                switch ((SortAlgsEnum)sortAlgComboBox.SelectedIndex)
                {
                case SortAlgsEnum.BUBBLE_SORT:
                    SortAlgs.BubbleSort(_sortedInt32Array, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                case SortAlgsEnum.INSERTION_SORT:
                    SortAlgs.InsertionSort(_sortedInt32Array, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                case SortAlgsEnum.QUICK_SORT:
                    SortAlgs.QuickSort(_sortedInt32Array, 0, _sortedInt32Array.Length - 1, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                case SortAlgsEnum.MERGE_SORT:
                    SortAlgs.MergeSort(_sortedInt32Array, 0, _sortedInt32Array.Length - 1, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                case SortAlgsEnum.HEAP_SORT:
                    SortAlgs.HeapSort(_sortedInt32Array, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                case SortAlgsEnum.PIGEON_SORT:
                    sortResultTextBlock.Text = "This algorithm does not support whole range of Int32 numbers.";
                    break;

                case SortAlgsEnum.COUNT_SORT:
                    sortResultTextBlock.Text = "This algorithm does not support whole range of Int32 numbers.";
                    error = true;
                    break;

                case SortAlgsEnum.RADIX_SORT:
                    SortAlgs.RadixSort(_sortedInt32Array, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                case SortAlgsEnum.SHELL_SORT:
                    SortAlgs.ShellSort(_sortedInt32Array, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                case SortAlgsEnum.BINARY_INSERTION_SORT:
                    SortAlgs.BinaryInsertionSort(_sortedInt32Array, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                default:
                    break;
                }
                break;

            case 3:
                switch ((SortAlgsEnum)sortAlgComboBox.SelectedIndex)
                {
                case SortAlgsEnum.BUBBLE_SORT:
                    SortAlgs.BubbleSort(_sortedInt64Array, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                case SortAlgsEnum.INSERTION_SORT:
                    SortAlgs.InsertionSort(_sortedInt64Array, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                case SortAlgsEnum.QUICK_SORT:
                    SortAlgs.QuickSort(_sortedInt64Array, 0, _sortedInt64Array.Length - 1, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                case SortAlgsEnum.MERGE_SORT:
                    SortAlgs.MergeSort(_sortedInt64Array, 0, _sortedInt64Array.Length - 1, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                case SortAlgsEnum.HEAP_SORT:
                    SortAlgs.HeapSort(_sortedInt64Array, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                case SortAlgsEnum.PIGEON_SORT:
                    sortResultTextBlock.Text = "This algorithm does not support whole range of Int64 numbers.";
                    error = true;
                    break;

                case SortAlgsEnum.COUNT_SORT:
                    sortResultTextBlock.Text = "This algorithm does not support whole range of Int64 numbers.";
                    error = true;
                    break;

                case SortAlgsEnum.RADIX_SORT:
                    SortAlgs.RadixSort(_sortedInt64Array, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                case SortAlgsEnum.SHELL_SORT:
                    SortAlgs.ShellSort(_sortedInt64Array, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                case SortAlgsEnum.BINARY_INSERTION_SORT:
                    SortAlgs.BinaryInsertionSort(_sortedInt64Array, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                default:
                    break;
                }
                break;

            case 4:
                switch ((SortAlgsEnum)sortAlgComboBox.SelectedIndex)
                {
                case SortAlgsEnum.BUBBLE_SORT:
                    SortAlgs.BubbleSort(_sortedStringArray, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                case SortAlgsEnum.INSERTION_SORT:
                    SortAlgs.InsertionSort(_sortedStringArray, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                case SortAlgsEnum.QUICK_SORT:
                    SortAlgs.QuickSort(_sortedStringArray, 0, _sortedStringArray.Length - 1, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                case SortAlgsEnum.MERGE_SORT:
                    SortAlgs.MergeSort(_sortedStringArray, 0, _sortedStringArray.Length - 1, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                case SortAlgsEnum.HEAP_SORT:
                    SortAlgs.HeapSort(_sortedStringArray, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                case SortAlgsEnum.PIGEON_SORT:
                    sortResultTextBlock.Text = "This algorithm is not suitable for strings.";
                    error = true;
                    break;

                case SortAlgsEnum.COUNT_SORT:
                    sortResultTextBlock.Text = "This algorithm is not suitable for strings.";
                    error = true;
                    break;

                case SortAlgsEnum.RADIX_SORT:
                    sortResultTextBlock.Text = "Type string is not supported for this algorithm yet...";
                    error = true;
                    break;

                case SortAlgsEnum.SHELL_SORT:
                    SortAlgs.ShellSort(_sortedStringArray, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                case SortAlgsEnum.BINARY_INSERTION_SORT:
                    SortAlgs.BinaryInsertionSort(_sortedStringArray, (sortOrderComboBox.SelectedIndex == 0));
                    break;

                default:
                    break;
                }
                break;
            }
        }