示例#1
0
        //METODOS ESTATISTICOS
        #region Bolha
        private void bolhaToolStripMenuItem1_Click_1(object sender, EventArgs e)
        {
            string preenchimento = "";

            vet = new int[Convert.ToInt32(comboBox1.SelectedValue)];

            if (radioAsc.Checked)
            {
                Preenchimento.Crescente(vet, tamanho);
                preenchimento = "Crescente";
            }
            else if (radioDec.Checked)
            {
                Preenchimento.Decrescente(vet, tamanho);
                preenchimento = "Decrescente";
            }
            else if (radioAleatorio.Checked)
            {
                Preenchimento.Aleatorio(vet, tamanho);
                preenchimento = "Aleatório";
            }


            var stopwatch = new Stopwatch();

            stopwatch.Start();                                 // inicia cronômetro
            OrdenacaoEstatistica.BubbleSort(vet);
            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 Bolha",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Information);

            OrdenacaoEstatistica.contTest   = 0; //ao final do método eu zero os contadores
            OrdenacaoEstatistica.contTrocas = 0;
        }