Пример #1
0
        private void quicksortToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            string preenchimento = "";

            vet = new int[Convert.ToInt32(comboBox1.SelectedValue)];
            Preenchimento.Aleatorio(vet, vet.Length);

            var stopwatch = new Stopwatch();

            stopwatch.Start(); // inicia cronômetro

            esq = 0;
            dir = vet.Length - 1;
            IniciarAnimacao(() => OrdenacaoEstatistica.QuickSort(vet, esq, dir));

            stopwatch.Stop();                                  // interrompe cronômetro
            long elapsed_time = stopwatch.ElapsedMilliseconds; // calcula o tempo decorrido

            MessageBox.Show(this,
                            "Tamanho do vetor: " + vet.Length +
                            "\nOrdenação inicial: " + preenchimento +
                            "\n\nTempo de execução: " + String.Format("{0:F4} seg", elapsed_time / 1000.0) +
                            "\nNº de comparações: " + OrdenacaoEstatistica.contTest +
                            "\nNº de trocas: " + OrdenacaoEstatistica.contTrocas,
                            "Estatísticas do Método QuickSort",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Information);

            OrdenacaoEstatistica.contTest   = 0;
            OrdenacaoEstatistica.contTrocas = 0;
        }