Esempio n. 1
0
        private async void button1_Click_1(object sender, EventArgs e)
        {
            var watch = System.Diagnostics.Stopwatch.StartNew();

            label4.Text   = "";
            textBox1.Text = String.Empty;
            long   Time;
            int    x   = 0;
            Random ran = new Random(99);


            if (radioButton1.Checked == true)
            {
                x = 10;
            }

            else if (radioButton2.Checked == true)
            {
                x = 100;
            }

            else if (radioButton3.Checked == true)
            {
                x = 1000;
            }

            else if (radioButton4.Checked == true)
            {
                x = 10000;
            }

            else if (radioButton5.Checked == true)
            {
                x = 100000;
            }

            else if (radioButton6.Checked == true)
            {
                x = 1000000;
            }

            else if (radioButton7.Checked == true)
            {
                x = 10000000;
            }

            int[] array = new int[x];

            for (int i = 0; i < x; i++)
            {
                array[i] = ran.Next(0, 99);
            }

            if (checkBox1.Checked == true)
            {
                array = await Task.Run(() => insert.insertionSortAsync(array));

                if (x == 10)
                {
                    foreach (int herpderp in array)
                    {
                        textBox1.Text += $"{herpderp}" + Environment.NewLine;
                    }
                }
            }

            if (checkBox2.Checked == true)
            {
                array = await Task.Run(() => m.mergeSortAsync(array));

                if (x == 10)
                {
                    foreach (int herpderp in array)
                    {
                        textBox1.Text += $"{herpderp}" + Environment.NewLine;
                    }
                }
            }

            if (checkBox3.Checked == true)
            {
                array = await Task.Run(() => h.heapsortAsync(array));

                if (x == 10)
                {
                    foreach (int herpderp in array)
                    {
                        textBox1.Text += $"{herpderp}" + Environment.NewLine;
                    }
                }
            }

            if (checkBox4.Checked == true)
            {
                array = await Task.Run(() => q.quicksortAsync(array));

                if (x == 10)
                {
                    foreach (int herpderp in array)
                    {
                        textBox1.Text += $"{herpderp}" + Environment.NewLine;
                    }
                }
            }
            watch.Stop();
            var elapsedMs = watch.ElapsedMilliseconds;

            Time        = (elapsedMs / 1000);
            label4.Text = "Sort(s) completed in " + elapsedMs.ToString() + " Milliseconds or " + Time.ToString() + " Second(s)";
        }