From e1eba01820919c0f982529872b154d19d451cb65 Mon Sep 17 00:00:00 2001 From: Fernando Erd <fce15@inf.ufpr.br> Date: Fri, 11 Dec 2015 23:55:46 -0200 Subject: [PATCH] =?UTF-8?q?Estrutura=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Arquivos/Loteria | Bin 13776 -> 13813 bytes Arquivos/Main.c | 59 ---------------------- Arquivos/MedirTempo.c | 63 +++++++++++++++++++++++ Arquivos/QuickSort.c | 113 ------------------------------------------ Arquivos/makefile | 3 +- 5 files changed, 65 insertions(+), 173 deletions(-) create mode 100644 Arquivos/MedirTempo.c delete mode 100644 Arquivos/QuickSort.c diff --git a/Arquivos/Loteria b/Arquivos/Loteria index f5cdde9c48e3384aa9ecd0c9209422479f765abc..6f3be512a0e027261422176357cf6e6f01e7ac94 100755 GIT binary patch delta 2262 zcmcbR{WW{S1<ozf3}CQj;?4bnH^jkgh8yAzV8)HfD;aN#eBj~HKBc$vcg{Wo?$!p` zD2+$|n>Np2y2UJTLDYf4<M_b@Fm;@ne{vJs4aO&vquKQse@yOTpXu~l)PZ3K$fy_V z|Nj4f-1QHL{aT{i^-t%q{fuHT$w`0z|8I8v!`NK=hqLa{el7+Eh8J;v|Nr05DmFQl zLyw73Z1Yr(QnuuP{Q_bR3@>(n`~Tmg*L8<S=dt}pa6?4D|Nr0Zx}*6AV+mjL4<`PW zFANL}FO3-)7(9Ai4|sGQf5GqrtnUJd?e*jT|NS7>yg2*q|NqY8FP44#|Nq6qZ<8~H z49qP+wrD|Y0jn<l`Tzgx==}*GaUmq}hahq1{T(3jUtcF*5E9|L`uG3;*NXdhfP`*< zg|bBc{r^9~qc`+`N3ZJzkIri#`|Tm_0-OHg`~Uy1T_BRjA;BfW1a>w^8X~Y4T_BAa zO@$;21H<MRVSh%R7w|CQ|1x>INQfRnVEt!kNW1=EY_9#mT(<}k7aZcSxaj>n`9Ghm za@}W8eBA(r&}$iwZr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6w`XtKnrR7l4>>1ghveNY+r03F7iNVTkN9sH`GXT$>9b-Us!P z=Hx(qaYhd?89ljCUtBVeiGe`?i~Fl5Z`2oOZDV3!P?&s?QJ8V+<cIp=hKr!)dWt~I z1t%;928NAH3=Dz{{0y)J!vb~30gz3Gm!P^pbs$J06+|#FFg${aGoyv<r^$r|;*#H? zvMf-$T%o$SCNDG)mlR}%`1~L*#3hMPS(V8b4a7~gm_fdhWT-%k6*H)=|AG)*;OxY} zz+lY`^QZr0Lql=N7^pg5XuO3%O;4SiXecgO50zcb2{EMsD%&-AqM<nJG`LwCCLc5u Ym)r(bZ4I>(7K7&|e>D8Q_^S~!0HD09CjbBd diff --git a/Arquivos/Main.c b/Arquivos/Main.c index a927373..dc9e274 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 0000000..02609f9 --- /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 ea70037..0000000 --- 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 430b929..9afeaa3 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 -- GitLab