private void cmdSort_Click(object sender, EventArgs e) { int speed = 100 - tbSpeed.Value; string alg1 = ""; string alg2 = ""; if (cboAlg1.SelectedItem != null) { alg1 = cboAlg1.SelectedItem.ToString(); } if (cboAlg2.SelectedItem != null) { alg2 = cboAlg2.SelectedItem.ToString(); } SortAlgorithm sa = new SortAlgorithm(array1, pnlSort1, true, txtOutputFolder.Text, speed, alg1); SortAlgorithm sa2 = new SortAlgorithm(array2, pnlSort2, true, txtOutputFolder.Text, speed, alg2); ThreadStart ts = delegate() { try { switch (alg1) { case "BiDirectional Bubble Sort": sa.BiDerectionalBubbleSort(array1); break; case "Bubble Sort": sa.BubbleSort(array1); break; case "Bucket Sort": sa.BucketSort(array1); break; case "Comb Sort": sa.CombSort(array1); break; case "Cycle Sort": sa.CycleSort(array1); break; case "Gnome Sort": sa.GnomeSort(array1); break; case "Heap Sort": sa.HeapSort(array1); break; case "Insertion Sort": sa.InsertionSort(array1); break; case "Merge Sort": sa.MergeSort(array1, 0, array1.Count - 1); break; case "Odd-Even Sort": sa.OddEvenSort(array1); break; case "Quick Sort": sa.QuickSort(array1, 0, array1.Count - 1); break; case "Quick Sort with Bubble Sort": sa.QuickSortWithBubbleSort(array1, 0, array1.Count - 1); break; case "Selection Sort": sa.SelectionSort(array1); break; case "Shell Sort": sa.ShellSort(array1); break; case "Pigeon Hole Sort": sa.PigeonHoleSort(array1); break; } if (chkAnimation.Checked) { sa.CreateAnimation(); } MessageBox.Show("Finish"); } catch (Exception err) { MessageBox.Show(err.Message); } }; ThreadStart ts2 = delegate() { try { switch (alg2) { case "BiDirectional Bubble Sort": sa2.BiDerectionalBubbleSort(array2); break; case "Bubble Sort": sa2.BubbleSort(array2); break; case "Bucket Sort": sa2.BucketSort(array2); break; case "Comb Sort": sa2.CombSort(array2); break; case "Cycle Sort": sa2.CycleSort(array2); break; case "Gnome Sort": sa2.GnomeSort(array2); break; case "Heap Sort": sa2.HeapSort(array2); break; case "Insertion Sort": sa2.InsertionSort(array2); break; case "Merge Sort": sa2.MergeSort(array2, 0, array2.Count - 1); break; case "Odd-Even Sort": sa2.OddEvenSort(array2); break; case "Quick Sort": sa2.QuickSort(array2, 0, array2.Count - 1); break; case "Quick Sort with Bubble Sort": sa2.QuickSortWithBubbleSort(array2, 0, array2.Count - 1); break; case "Selection Sort": sa2.SelectionSort(array2); break; case "Shell Sort": sa2.ShellSort(array2); break; case "Pigeon Hole Sort": sa2.PigeonHoleSort(array2); break; } if (chkAnimation.Checked) { sa2.CreateAnimation(); } MessageBox.Show("Finish"); } catch (Exception err) { MessageBox.Show(err.Message); } }; if (alg1 != "") { Thread t = new Thread(ts); t.Start(); } if (alg2 != "") { Thread t2 = new Thread(ts2); t2.Start(); } }
private void butonSort_click(object sender, EventArgs e) { if (thread1 != null) { thread1.Abort(); thread1.Join(); } if (thread2 != null) { thread2.Abort(); thread2.Join(); } siralamaHazirlik(); if (cbDiziTipleri.SelectedItem.ToString() == "Rastgele") { // çalışmaya hazır, ek işleme gerek yok. } else if (cbDiziTipleri.SelectedItem.ToString() == "Sıralı") { array1.Sort(); array2 = (ArrayList)array1.Clone(); } else if (cbDiziTipleri.SelectedItem.ToString() == "Tersten Sıralı") { array1.Sort(); array1.Reverse(); array2 = (ArrayList)array1.Clone(); } resizeGraphics(); int speed = 1; for (int i = 0; i < tbHiz.Value; i++) { speed *= 2; } string alg1 = ""; string alg2 = ""; if (cbAlg1.SelectedItem != null) { alg1 = cbAlg1.SelectedItem.ToString(); } if (cbAlg2.SelectedItem != null) { alg2 = cbAlg2.SelectedItem.ToString(); } SortAlgorithm sa = new SortAlgorithm(array1, pbSort1, speed); SortAlgorithm sa2 = new SortAlgorithm(array2, pbSort2, speed); ThreadStart ts = delegate() { var watch = new System.Diagnostics.Stopwatch(); watch.Start(); switch (alg1) { case "Counting Sort": sa.CountingSort(array1); break; case "Selection Sort": sa.SelectionSort(array1); break; } sa.cizimiBitir(); watch.Stop(); lblAlg1CalismaSuresi.Text = $"{ watch.ElapsedMilliseconds} ms"; if (!dizi_siralandiMi(array1)) { MessageBox.Show("#1 Sort Failed!"); } }; ThreadStart ts2 = delegate() { var watch = new System.Diagnostics.Stopwatch(); watch.Start(); switch (alg2) { case "Counting Sort": sa2.CountingSort(array2); break; case "Selection Sort": sa2.SelectionSort(array2); break; } sa2.cizimiBitir(); watch.Stop(); lblAlg2CalismaSuresi.Text = $"{ watch.ElapsedMilliseconds} ms"; if (!dizi_siralandiMi(array2)) { MessageBox.Show("#2 Sort Failed!"); } }; if (alg1 != "") { thread1 = new Thread(ts); thread1.Start(); } if (alg2 != "") { thread2 = new Thread(ts2); thread2.Start(); } }