Exemple #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("Демонстрация завершена");
            }
        }
Exemple #2
0
 private void SortBtn_Click(object sender, EventArgs e)
 {
     try
     {
         SortArr(DGVhelp.ToArray(InputDataDGV));
     }
     catch (Exception ex)
     {
         MessagesUtils.ShowError("Произошла ошибка. Проверьте корректность ваших данных");
     }
 }
Exemple #3
0
        private void FillBtn_Click(object sender, EventArgs e)
        {
            try
            {
                int count = int.Parse(MessagesUtils.Prompt("Укажите число элементов", "Заполнение массива"));

                DGVhelp.Fill(InputDataDGV, GenerateRandomArr(count));
            }
            catch (Exception ex)
            {
                MessagesUtils.ShowError("Укажите корректное число элементов");
            }
        }
Exemple #4
0
        private void ShuffleBtn_Click(object sender, EventArgs e)
        {
            int[] arr = DGVhelp.ToArray(InputDataDGV);

            for (int i = 0; i < arr.Length - 1; i++)
            {
                int index = _rnd.Next(i + 1, arr.Length - 1);

                int t = arr[i];
                arr[i]     = arr[index];
                arr[index] = t;
            }

            DGVhelp.Fill(InputDataDGV, arr);
        }
Exemple #5
0
        private void SortDemonstateBtn_Click(object sender, EventArgs e)
        {
            try
            {
                int[] arr = DGVhelp.ToArray(InputDataDGV);

                if (arr.Length > 15)
                {
                    throw new Exception("Укажите массив размером до 15 элементов");
                }

                sortsStatsTabs.SelectedTab = sortsDemonstationTab;
                SortArr(arr, true);
            }
            catch (Exception ex)
            {
                MessagesUtils.ShowError("Произошла ошибка. Проверьте корректность ваших данных");
            }
        }
Exemple #6
0
 private void ClearBtn_Click(object sender, EventArgs e)
 {
     DGVhelp.Clear(InputDataDGV);
 }