예제 #1
0
 public void DisplaySortStatistic(AlgorithmsBase <SortedItem> sort, TimeSpan time)
 {
     timeLabel.Text        = "Time: " + time.TotalSeconds.ToString() + " s";
     comparisonsLabel.Text = "Comparisons: " + sort.ComparisonCount;
     swopLabel.Text        = "Swops: " + sort.SwopCount;
     setLabel.Text         = "Sets: " + sort.SetCount;
 }
예제 #2
0
 private void AnalysisAlgorithm(AlgorithmsBase <int> algorithmsBase, List <int> Items, List <TimeSpan> timeSpan, List <int> swapCount)
 {
     algorithmsBase.Items.AddRange(Items);
     timeSpan.Add(algorithmsBase.Sort());
     swapCount.Add(algorithmsBase.SwapCount);
     algorithmsBase.Items.Clear();
 }
예제 #3
0
 public void SortTest(AlgorithmsBase <int> toSort)
 {
     //FillRandom(ref Item);
     toSort.AddRange(Item);
     Item.Sort();
     toSort.TimeToSort();
     for (int i = 0; i < Item.Count; i++)
     {
         Assert.AreEqual(toSort.Items[i], Item[i]);
     }
 }
예제 #4
0
        public void BaseSortTest()
        {
            // Arrange
            var base_sort = new AlgorithmsBase <int>();

            base_sort.Items.AddRange(Items);

            // Act
            base_sort.Sort();

            // Assest
            for (int i = 0; i < Items.Count; i++)
            {
                Assert.AreEqual(Sorted[i], base_sort.Items[i]);
            }
        }
예제 #5
0
        private void buttonSort_Click(object sender, EventArgs e)
        {
            sorted = (AlgorithmsBase <SortedItem>)TypeSortListBox.SelectedItem;
            if (sorted == null)
            {
                labelSorted.Text = "Type sort is not selected";
                return;
            }
            TimeSpan time;

            labelSorted.Text = "";
            ClearPanelItem();
            sorted.Items.Clear();
            if (checkBoxVisualize.Checked)
            {
                sorted.CompareEvent += CompareEvent;
                sorted.SwopEvent    += SwopEvent;
                sorted.SetEvent     += SetEvent;
            }
            sorted.AddRange(ConvertToSortedItem(toSort.Items));
            DisplayPanelItemSorted(sorted.Items);
            try
            {
                time = sorted.TimeToSort();
            }
            catch (NotImplementedException)
            {
                labelSorted.Text = "Type sort is not corrected " + nameof(sorted);
                return;
            }
            DisplayItems(labelSorted, sorted.Items);
            DisplaySortStatistic(sorted, time);
            sorted.CompareEvent -= CompareEvent;
            sorted.SwopEvent    -= SwopEvent;
            sorted.SetEvent     -= SetEvent;
        }
예제 #6
0
        public BuubleSortForm(string rText, int param)
        {
            InitializeComponent();
            richTextBox1.Text = rText;

            switch (param)
            {
            case 1:
            {
                algorithmsBase = new BubbleSort <int>();
                this.Text      = Constants.BubbleSort;
            }
            break;

            case 2:
            {
                algorithmsBase = new CoctailSort <int>();
                this.Text      = Constants.CoctailSort;
            }
            break;

            case 3:
            {
                algorithmsBase = new InsertSort <int>();
                this.Text      = Constants.InsertionSort;
            }
            break;

            case 4:
            {
                algorithmsBase = new ShellSort <int>();
                this.Text      = Constants.ShellSort;
            }
            break;

            case 5:
            {
                algorithmsBase = new HeapSort <int>();
                this.Text      = Constants.HeapSort;
            }
            break;

            case 6:
            {
                algorithmsBase = new TreeSort <int>();
                this.Text      = Constants.TreeSort;
            }
            break;

            case 7:
            {
                algorithmsBase = new SelectionSort <int>();
                this.Text      = Constants.SelectionSort;
            }
            break;

            case 8:
            {
                algorithmsBase = new GnomeSort <int>();
                this.Text      = Constants.GnomeSort;
            }
            break;

            case 9:
            {
                algorithmsBase = new MergeSort <int>();
                this.Text      = Constants.MergeSort;
            }
            break;

            case 10:
            {
                algorithmsBase = new QuickSort <int>();
                this.Text      = Constants.QuickSort;
            }
            break;

            default: { } break;
            }
        }
예제 #7
0
        private async void Button3_Click(object sender, EventArgs e)
        {
            AlgorithmsBase <int> algorithmsBase = null;
            var Items     = new List <int>();
            var timeSpan  = new List <TimeSpan>();
            var swapCount = new List <int>();

            richTextBoxParser(Items);

            #region Методы для вычисления сортировок.

            algorithmsBase = new BubbleSort <int>();
            await Task.Run(() => AnalysisAlgorithm(algorithmsBase, Items, timeSpan, swapCount));

            await Task.Run(() => richTextBox2.Invoke((Action) delegate
            {
                richTextBoxFill(Constants.BubbleSort, timeSpan[0], swapCount[0]);
            }
                                                     ));

            algorithmsBase = new CoctailSort <int>();
            await Task.Run(() => AnalysisAlgorithm(algorithmsBase, Items, timeSpan, swapCount));

            await Task.Run(() => richTextBox2.Invoke((Action) delegate
            {
                richTextBoxFill(Constants.CoctailSort, timeSpan[1], swapCount[1]);
            }
                                                     ));

            algorithmsBase = new InsertSort <int>();
            await Task.Run(() => AnalysisAlgorithm(algorithmsBase, Items, timeSpan, swapCount));

            await Task.Run(() => richTextBox2.Invoke((Action) delegate
            {
                richTextBoxFill(Constants.InsertionSort, timeSpan[2], swapCount[2]);
            }
                                                     ));

            algorithmsBase = new ShellSort <int>();
            await Task.Run(() => AnalysisAlgorithm(algorithmsBase, Items, timeSpan, swapCount));

            await Task.Run(() => richTextBox2.Invoke((Action) delegate
            {
                richTextBoxFill(Constants.ShellSort, timeSpan[3], swapCount[3]);
            }
                                                     ));

            algorithmsBase = new HeapSort <int>();
            await Task.Run(() => AnalysisAlgorithm(algorithmsBase, Items, timeSpan, swapCount));

            await Task.Run(() => richTextBox2.Invoke((Action) delegate
            {
                richTextBoxFill(Constants.HeapSort, timeSpan[4], swapCount[4]);
            }
                                                     ));

            algorithmsBase = new TreeSort <int>();
            await Task.Run(() => AnalysisAlgorithm(algorithmsBase, Items, timeSpan, swapCount));

            await Task.Run(() => richTextBox2.Invoke((Action) delegate
            {
                richTextBoxFill(Constants.TreeSort, timeSpan[5], swapCount[5]);
            }
                                                     ));

            algorithmsBase = new SelectionSort <int>();
            await Task.Run(() => AnalysisAlgorithm(algorithmsBase, Items, timeSpan, swapCount));

            await Task.Run(() => richTextBox2.Invoke((Action) delegate
            {
                richTextBoxFill(Constants.SelectionSort, timeSpan[6], swapCount[6]);
            }
                                                     ));

            algorithmsBase = new GnomeSort <int>();
            await Task.Run(() => AnalysisAlgorithm(algorithmsBase, Items, timeSpan, swapCount));

            await Task.Run(() => richTextBox2.Invoke((Action) delegate
            {
                richTextBoxFill(Constants.GnomeSort, timeSpan[7], swapCount[7]);
            }
                                                     ));

            algorithmsBase = new MergeSort <int>();
            await Task.Run(() => AnalysisAlgorithm(algorithmsBase, Items, timeSpan, swapCount));

            await Task.Run(() => richTextBox2.Invoke((Action) delegate
            {
                richTextBoxFill(Constants.MergeSort, timeSpan[8], swapCount[8]);
            }
                                                     ));

            algorithmsBase = new QuickSort <int>();
            await Task.Run(() => AnalysisAlgorithm(algorithmsBase, Items, timeSpan, swapCount));

            await Task.Run(() => richTextBox2.Invoke((Action) delegate
            {
                richTextBoxFill(Constants.QuickSort, timeSpan[9], swapCount[9]);
            }
                                                     ));

            #endregion

            button3.Enabled = false;

            string[] seriesArray = new string[10];
            int[]    pointsArray = new int[10];

            chart1.Series.Clear();
            var countSeries = 0;
            checkBoxCheckedAll(ref countSeries, seriesArray, pointsArray, swapCount);
            chartDefaultSettings(countSeries, pointsArray.Max());

            for (int i = 0; i < seriesArray.Length; i++)
            {
                if (seriesArray[i] != null)
                {
                    Series series = chart1.Series.Add(seriesArray[i]);
                    series.Points.Add(pointsArray[i]);
                }
            }
        }