예제 #1
0
        private void SortArr(int[] arr, bool visualize = false, int swapInterval = 100)
        {
            if (visualize)
            {
                Sorter.DemonstrationControl = CanvasPanel;
            }

            if (bubbleSortRadio.Checked)
            {
                Sorter.BubbleSort(arr, 0, arr.Length - 1);
            }
            else if (twoWaysInsertionSortRadio.Checked)
            {
                Sorter.TwoWaysInsertionSort(arr, 0, arr.Length - 1);
            }
            else
            {
                DoubleLinkedList list = new DoubleLinkedList(arr);
                Sorter.TwoWaysListInsertionSort(ref list);
                arr = list.ToArray();
            }

            ComparsionsCountLbl.Text = Sorter.ComparsionsCount.ToString();
            SwapsCountLbl.Text       = Sorter.SwapsCount.ToString();

            DGVhelp.Fill(InputDataDGV, arr);

            Sorter.DemonstrationControl = null;

            if (visualize)
            {
                MessageBox.Show("Демонстрация завершена");
            }
        }
        public static void DrawChart(Chart chart,
                                     int[] testArr,
                                     ChartType type = ChartType.Comparsions)
        {
            Form prompt = new Form()
            {
                Width           = 500,
                Height          = 100,
                FormBorderStyle = FormBorderStyle.FixedDialog,
                Text            = "Построение графика",
                StartPosition   = FormStartPosition.CenterScreen
            };

            ProgressBar progressBar = new ProgressBar()
            {
                Left = 10, Width = 450, Top = 20, Height = 20
            };

            progressBar.Value = 0;
            prompt.Controls.Add(progressBar);

            prompt.Show();

            var twoWaysInsertions = chart.Series[0];

            twoWaysInsertions.Points.Clear();

            var twoWaysInsertionsList = chart.Series[1];

            twoWaysInsertionsList.Points.Clear();

            var bubbleSort = chart.Series[2];

            bubbleSort.Points.Clear();

            int[] arr = (int[])testArr.Clone();

            progressBar.Minimum = 0;
            progressBar.Maximum = (testArr.Length * 3);

            for (int i = 1; i < testArr.Length; i++)
            {
                arr = (int[])testArr.Clone();
                Sorter.TwoWaysInsertionSort(arr, 0, i);
                twoWaysInsertions.Points.AddXY(i,
                                               (type == ChartType.Comparsions) ? Sorter.ComparsionsCount : Sorter.SwapsCount);

                progressBar.Value++;

                arr = new int[i + 1];
                Array.Copy(testArr, 0, arr, 0, i);

                DoubleLinkedList list = new DoubleLinkedList(arr);
                Sorter.TwoWaysListInsertionSort(ref list);
                twoWaysInsertionsList.Points.AddXY(i,
                                                   (type == ChartType.Comparsions) ? Sorter.ComparsionsCount : Sorter.SwapsCount);

                progressBar.Value++;

                arr = (int[])testArr.Clone();
                Sorter.BubbleSort(arr, 0, i);
                bubbleSort.Points.AddXY(i,
                                        (type == ChartType.Comparsions) ? Sorter.ComparsionsCount : Sorter.SwapsCount);

                progressBar.Value++;
            }

            prompt.Close();
        }