Example #1
0
        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();
            }
        }