Пример #1
0
        private void mergesortToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            int tamanhoVet = DefineTamanho();

            int[]  vetor         = new int[tamanhoVet];
            string nomeOrdenacao = "";

            vetor = PreecheVetTipo(vetor, out nomeOrdenacao, tamanhoVet);

            OrdenacaoEstatistica.cont_c = 0;
            OrdenacaoEstatistica.cont_t = 0;

            var stopwatch = new Stopwatch();

            stopwatch.Start();                                 // inicia cronômetro
            OrdenacaoEstatistica.MergeSort(vetor, 0, vetor.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: {nomeOrdenacao}" +
                            "\n\nTempo de execução: " + String.Format("{0:F4} seg", elapsed_time / 1000.0) +
                            $"\nNº de comparações: {OrdenacaoEstatistica.cont_c}" +
                            $"\nNº de trocas: {OrdenacaoEstatistica.cont_t}",
                            "Estatísticas do Método MergeSort",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Information);
        }
Пример #2
0
        private void mergesortToolStripMenuItem_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

            int i, j;

            i = 0;
            j = vet.Length - 1;
            IniciarAnimacao(() => OrdenacaoEstatistica.MergeSort(vet, i, j));

            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 MergeSort",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Information);
            OrdenacaoEstatistica.contTest   = 0;
            OrdenacaoEstatistica.contTrocas = 0;
        }