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("Демонстрация завершена"); } }
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("Укажите корректное число элементов"); } }
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); }