예제 #1
0
        private void quicksortToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            int tamanhovet = Convert.ToInt32(comboBox1.Text);

            int[]  vetor       = new int[tamanhovet]; // TODO (tamanho deverá ser escolhido pelo usuário)
            string auxPreenchi = "";

            int[] vetReturn = new int[2];

            if (rdbCresc.Checked == true)
            {
                Preenchimento.Crescente(vetor);
                auxPreenchi = "Crescente";
            }
            else if (rdbDesc.Checked == true)
            {
                Preenchimento.Decrescente(vetor);
                auxPreenchi = "Decrescente";
            }
            else
            {
                Preenchimento.Aleatorio(vetor, 1000);
                auxPreenchi = "Aleatório";
            }

            var stopwatch = new Stopwatch();

            stopwatch.Start();                                 // inicia cronômetro
            vetReturn = OrdenacaoEstatistica.quickSortAux(vetor, 0, vet.Length - 1);
            stopwatch.Stop();                                  // interrompe cronômetro
            long elapsed_time = stopwatch.ElapsedMilliseconds; // calcula o tempo decorrido

            MessageBox.Show(this,
                            "Tamanho do vetor: " + tamanhovet +
                            "\nOrdenação inicial: " + auxPreenchi +
                            "\n\nTempo de execução: " + String.Format("{0:F4} seg", elapsed_time / 1000.0) +
                            "\nNº de comparações: " + vetReturn[0] +
                            "\nNº de trocas: " + vetReturn[1],
                            "Estatísticas do Método Quicksort",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Information);
        }