diff --git a/Arquivos/Loteria b/Arquivos/Loteria index f5cdde9c48e3384aa9ecd0c9209422479f765abc..6f3be512a0e027261422176357cf6e6f01e7ac94 100755 Binary files a/Arquivos/Loteria and b/Arquivos/Loteria differ diff --git a/Arquivos/Main.c b/Arquivos/Main.c index a927373764d4520bb6225b5b079b77b0ae16eb73..dc9e2743b553f83549dd54af8b25d9586bf4cf1c 100644 --- a/Arquivos/Main.c +++ b/Arquivos/Main.c @@ -1,65 +1,6 @@ #include "Estruturas.h" #include "Funções.h" -//Calcula o Tempo da Execução do SelectSort -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); -} - -//Calcula o Tempo da Execução do BubbleSort -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); -} - -//Calcula o Tempo da Execução do QuickSort Recursivo -void TempoQuickSortRecursivo (int *Vetor) { - struct timeval inicio, final; - int tmili, i; - - gettimeofday(&inicio, NULL); - for (i = 0; i < 10000; i ++) { - GeraVetor(Vetor); - QuickSortRecursivo (Vetor, 0, TAM); - } - gettimeofday(&final, NULL); - tmili = (int) (1000 * (final.tv_sec - inicio.tv_sec) + (final.tv_usec - inicio.tv_usec) / 1000); - printf ("O QuickSort Recursivo Demorou %d Centesimos\n", tmili); -} - -//Calcula o Tempo da Execução do QuickSort Iterativo -void TempoQuickSortIterativo (int *Vetor) { - struct timeval inicio, final; - int tmili, i; - - gettimeofday(&inicio, NULL); - for (i = 0; i < 10000; i ++) { - GeraVetor(Vetor); - QuickSortIterativo (Vetor, 0, TAM); - } - gettimeofday(&final, NULL); - tmili = (int) (1000 * (final.tv_sec - inicio.tv_sec) + (final.tv_usec - inicio.tv_usec) / 1000); - printf ("O QuickSort Iterativo Demorou %d Centesimos\n", tmili); -} int main () { int Vetor[TAM], Escolhidos[4]; diff --git a/Arquivos/MedirTempo.c b/Arquivos/MedirTempo.c new file mode 100644 index 0000000000000000000000000000000000000000..02609f93fc275e287a99de5764a2655ddf803fd1 --- /dev/null +++ b/Arquivos/MedirTempo.c @@ -0,0 +1,63 @@ +#include "Funções.h" +#include "Estruturas.h" + +//Calcula o Tempo da Execução do SelectSort +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); +} + +//Calcula o Tempo da Execução do BubbleSort +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); +} + +//Calcula o Tempo da Execução do QuickSort Recursivo +void TempoQuickSortRecursivo (int *Vetor) { + struct timeval inicio, final; + int tmili, i; + + gettimeofday(&inicio, NULL); + for (i = 0; i < 10000; i ++) { + GeraVetor(Vetor); + QuickSortRecursivo (Vetor, 0, TAM); + } + gettimeofday(&final, NULL); + tmili = (int) (1000 * (final.tv_sec - inicio.tv_sec) + (final.tv_usec - inicio.tv_usec) / 1000); + printf ("O QuickSort Recursivo Demorou %d Centesimos\n", tmili); +} + +//Calcula o Tempo da Execução do QuickSort Iterativo +void TempoQuickSortIterativo (int *Vetor) { + struct timeval inicio, final; + int tmili, i; + + gettimeofday(&inicio, NULL); + for (i = 0; i < 10000; i ++) { + GeraVetor(Vetor); + QuickSortIterativo (Vetor, 0, TAM); + } + gettimeofday(&final, NULL); + tmili = (int) (1000 * (final.tv_sec - inicio.tv_sec) + (final.tv_usec - inicio.tv_usec) / 1000); + printf ("O QuickSort Iterativo Demorou %d Centesimos\n", tmili); +} + diff --git a/Arquivos/QuickSort.c b/Arquivos/QuickSort.c deleted file mode 100644 index ea70037e2bd1d21181479a233dcc63d6492a42b3..0000000000000000000000000000000000000000 --- a/Arquivos/QuickSort.c +++ /dev/null @@ -1,113 +0,0 @@ -#include <stdio.h> - -void Troca (int *Vetor, int i, int j) { - int aux; - - aux = Vetor[i]; - Vetor [i] = Vetor[j]; - Vetor [j] = aux; -} - -void printVetor( int Vetor[], int n ) { - int i; - for ( i = 0; i < n; ++i ) - printf( "%d ", Vetor[i] ); - printf ("\n"); -} - -int Mediana(int *Vetor, int esq, int dir) { - int aux; - aux = (dir+esq)/2; // elem. do meio do vetor - - //mediana dos 3 numeros - - if ( (Vetor[esq] >= Vetor[aux]) && (Vetor[esq] <= Vetor[dir]) ) - return esq; - - else if ( (Vetor[esq] >= Vetor[dir]) && (Vetor[esq] <= Vetor[aux]) ) - return esq; - - else if ( (Vetor[dir] >= Vetor[aux]) && (Vetor[dir] <= Vetor[esq]) ) - return dir; - - else if ( (Vetor[dir] >= Vetor[esq]) && (Vetor[dir] <= Vetor[aux]) ) - return dir; - - else if ( (Vetor[aux] >= Vetor[esq]) && (Vetor[aux] <= Vetor[dir]) ) - return aux; - - else if ( (Vetor[aux] >= Vetor[dir]) && (Vetor[aux] <= Vetor[esq]) ) - return aux; - -} - -int Particao (int *Vetor, int esq, int dir) { - int i,j,pivo,aux; - aux = Mediana(Vetor,esq,dir); - pivo = Vetor[aux]; - printf("%d\n",pivo); - i = esq; - j = dir; - while (i < j) { - - while ( (Vetor[i] <= pivo) && (i < dir) ) - i++; - - while (Vetor[j] > pivo) - j--; - - if (i < j) - Troca(Vetor,j,i); - } - - printVetor(Vetor,18); - Vetor[esq] = Vetor[j]; - Vetor[j] = pivo; - return j; -} - -void QuickSortRecursivo (int Vetor[], int Esquerda, int Direita) { - int pospivo; - if (Esquerda < Direita) { - pospivo = Particao(Vetor, Esquerda, Direita); - QuickSortRecursivo(Vetor,Esquerda,pospivo-1); - QuickSortRecursivo(Vetor,pospivo+1,Direita); - } -} -void QuickSortIterativo (int Vetor[], int Esquerda, int Direita) { - int Posicao; - int Pilha[ Direita - Esquerda + 1 ]; - int top; - - top = -1; - Pilha[ ++top ] = Esquerda; - Pilha[ ++top ] = Direita; - - while ( top >= 0 ) - { - Direita = Pilha[ top-- ]; - Esquerda = Pilha[ top-- ]; - - Posicao = Particao( Vetor, Esquerda, Direita ); - - if ( Posicao-1 > Esquerda ) - { - Pilha[ ++top ] = Esquerda; - Pilha[ ++top ] = Posicao - 1; - } - - if ( Posicao+1 < Direita ) - { - Pilha[ ++top ] = Posicao + 1; - Pilha[ ++top ] = Direita; - } - } -} - -int main() { - int Vetor[] = {1,2,3,4,5,8,6,4,43,43,56,23,43,4,3,75,342,532}; - int n = sizeof( Vetor ) / sizeof( *Vetor ); - printVetor (Vetor, n); - QuickSortIterativo( Vetor, 0, n - 1 ); - printVetor( Vetor, n ); -} diff --git a/Arquivos/makefile b/Arquivos/makefile index 430b929f1e6d5d35ca54d1ddc1d1a7e399d47dd6..9afeaa32aa603ec26fa5e2efc5349fbe5f9b27db 100644 --- a/Arquivos/makefile +++ b/Arquivos/makefile @@ -2,7 +2,8 @@ all: gcc -c Vetor.c gcc -c Ordenação.c gcc -c Pesquisa.c + gcc -c MedirTempo.c gcc -c Main.c - gcc Vetor.o Ordenação.o Main.o Pesquisa.o -o Loteria -g + gcc Vetor.o Ordenação.o Main.o Pesquisa.o MedirTempo.o -o Loteria -g rm *.o