示例#1
0
 public SortingBenchmark()
 {
     bubbleSort = new BubbleSort();
     combSort = new CombSort();
     countSort = new CountSort();
     heapSort = new HeapSort();
     insertionSort = new InsertionSort();
     mergeSort = new MergeSort();
     partitionedMergeSort = new PartitionedMergeSort();
     quickSort = new QuickSort();
     quickSortLomuto = new QuickSort_Lomuto();
     radixSort = new RadixSort();
     selectionSort = new SelectionSort();
     shellSort = new ShellSort();
 }
示例#2
0
        static void PerformInsertionSort(int sizeArray)
        {
            SortingAlgorithms sorting = new CountSort(sizeArray);

            sorting.FillArray();
            Stopwatch watch = new Stopwatch();

            watch.Start();
            sorting.SortArray();
            watch.Stop();
            var arr = sorting.GetSortedArray;

            Print(arr);
            Console.WriteLine($"Total Execution Time: {watch.ElapsedMilliseconds} ms");
        }
示例#3
0
        // Complete the activityNotifications function below.
        public static int activityNotifications(int[] expenditure, int d)
        {
            var ct = new CountSort(expenditure.Take(d));

            var notifications = 0;

            for (int i = d; i < expenditure.Length; i++)
            {
                var median = ct.GetMedian();

                if (expenditure[i] >= 2 * median)
                {
                    notifications++;
                }

                ct.Update(expenditure[i - d], expenditure[i]);
            }
            return(notifications);
        }
示例#4
0
        private void buttonSort_Click(object sender, EventArgs e)
        {
            this.tmp.CopyTo(array, 0);
            int tmp = _radioButtonList.FindIndex(button => button.Checked);

            switch (tmp)
            {
            case 0:
            {
                _comparator = new NumberComparator();
                _sortable   = new BubbleSorter <double>();
            }
            break;

            case 1:
            {
                _comparator = new NumberComparator();
                _sortable   = new FlagBubble <double>();
            }
            break;

            case 2:
            {
                _comparator = new NumberComparator();
                _sortable   = new SimpleSelection <double>();
            }
            break;

            case 3:
            {
                _comparator = new NumberComparator();
                _sortable   = new QuickSort <double>();
            }
            break;

            case 4:
            {
                IComparableLab <CustomDoubleArray> comparator = new CustomDoubleArrayComparator();
                ISortable <CustomDoubleArray>      sortable   = new ShellSort <CustomDoubleArray>();
                if (sortable.ArrayCheck(CustomDoubleArray, comparator))
                {
                    tmpArrayHolder.Text    = "";
                    sortedArrayHolder.Text = "";

                    CustomDoubleArray = sortable.Sort(CustomDoubleArray, tmpArrayHolder, comparator, true, true);
                    sortable.Print(CustomDoubleArray, sortedArrayHolder, "");
                }
                else
                {
                    tmpLabel.Text = "Please reenter array, because it does not fit the condition!!";
                }
            }
                return;

            case 5:
            {
                _comparator = new NumberComparator();
                _sortable   = new MergeSort <double>();
                _direction  = false;
            }
            break;

            case 6:
            {
                int [] intArray = new int[array.Length];
                for (int i = 0; i < intArray.Length; i++)
                {
                    intArray[i] = (int)array[i];
                }

                intArray = Lab6ArrayHandler.Execute(intArray);
                IComparableLab <int> comparable = new NumberComparator();
                ISortable <int>      sortable   = new CountSort <int>();
                _direction = false;
                if (sortable.ArrayCheck(intArray, comparable))
                {
                    tmpArrayHolder.Text    = "";
                    sortedArrayHolder.Text = "";
                    sortable.Print(intArray, tmpArrayHolder, "Масив після виконання індивідуального завдання: \n");
                    intArray = sortable.Sort(intArray, tmpArrayHolder, comparable, _direction, true);
                    sortable.Print(intArray, sortedArrayHolder, "");
                }
                else
                {
                    tmpLabel.Text = "Please reenter array, because it does not fit the condition!!";
                }
            }
                return;

            default:
            {
                throw new IndexOutOfRangeException();
            }
            }

            if (_sortable.ArrayCheck(array, _comparator))
            {
                tmpArrayHolder.Text    = "";
                sortedArrayHolder.Text = "";

                array = _sortable.Sort(array, tmpArrayHolder, _comparator, _direction, true);
                _sortable.Print(array, sortedArrayHolder, "");
            }
            else
            {
                tmpLabel.Text = "Please reenter array, because it does not fit the condition!!";
            }
        }