diff --git a/Arquivos/Estruturas.h b/Arquivos/Estruturas.h index e481e12d956610042797aaf74535466b2aa12a19..4ecf344e5c95cac3a9882799d7b7121fa9de7312 100644 --- a/Arquivos/Estruturas.h +++ b/Arquivos/Estruturas.h @@ -4,5 +4,5 @@ #include <stdlib.h> #include <stdbool.h> #include <sys/time.h> -#define TAM 15 //tamanho do vetor +#define TAM 100 //tamanho do vetor #define NUMMAX 50 //constante que tem o máximo de valores diff --git a/Arquivos/Loteria b/Arquivos/Loteria index f2fd0e853897eb862df53e08efb4fb7fe483f85a..3380a6027ca5e43394153b3fe944f969084885ca 100755 Binary files a/Arquivos/Loteria and b/Arquivos/Loteria differ diff --git a/Arquivos/Main.c b/Arquivos/Main.c index c7dcc9ba7c570a0f96b5e7d6c5787b2ccf5c286c..57b25dde8307697eeae618e521a6440b243ea842 100644 --- a/Arquivos/Main.c +++ b/Arquivos/Main.c @@ -1,10 +1,37 @@ #include "Estruturas.h" #include "Funções.h" +void TempoSelectSort (int *Vetor) { + struct timeval inicio, final; + int tmili, i; + + gettimeofday(&inicio, NULL); + for (i = 0; i < 10000; i ++) { + GeraVetor(Vetor); + SelectSort (Vetor); + } + gettimeofday(&final, NULL); + tmili = (int) (1000 * (final.tv_sec - inicio.tv_sec) + (final.tv_usec - inicio.tv_usec) / 1000); + printf ("O SelectSort Demorou %d Centesimos\n", tmili); +} + +void TempoBubbleSort (int *Vetor) { + struct timeval inicio, final; + int tmili, i; + + gettimeofday(&inicio, NULL); + for (i = 0; i < 10000; i ++) { + GeraVetor(Vetor); + BubbleSort (Vetor); + } + gettimeofday(&final, NULL); + tmili = (int) (1000 * (final.tv_sec - inicio.tv_sec) + (final.tv_usec - inicio.tv_usec) / 1000); + printf ("O BubbleSort Demorou %d Centesimos\n", tmili); +} + int main () { int Vetor[TAM], Escolhidos[4]; - struct timeval inicio, final; - int tmili, i, comando; + int comando; printf ("1 Para Jogar e 2 Para Comparar Algoritmos\n"); scanf ("%d", &comando); @@ -17,13 +44,7 @@ int main () { ImprimeVetor (Vetor); break; case 2: - gettimeofday(&inicio, NULL); - for (i = 0; i < 10000; i ++) { - GeraVetor(Vetor); - SelectSort (Vetor); - } - gettimeofday(&final, NULL); - tmili = (int) (1000 * (final.tv_sec - inicio.tv_sec) + (final.tv_usec - inicio.tv_usec) / 1000); - printf ("O SelectSort Demorou %d Centesimos\n", tmili); + TempoSelectSort (Vetor); + TempoBubbleSort (Vetor); } } diff --git a/Arquivos/Pesquisa.c b/Arquivos/Pesquisa.c index 740af532b14effe574b3a3c71f5f514ebe37a6d6..033a1c5eefaf3d00ae4c7b87d6f1473223bfa1ef 100644 --- a/Arquivos/Pesquisa.c +++ b/Arquivos/Pesquisa.c @@ -23,10 +23,11 @@ int PesquisaBinaria (int *Vetor, int Elem) { int PesquisaSequencial(int *Vetor, int Elem) { int i; Vetor[0] = Elem; - for (i=TAM-1; i>=0; i++) { + for (i = 0; i < TAM; i++) { if (Vetor[i] == Elem) return i; } + return -1; //-1 pq o elemento pode estar na posição zero }