diff --git a/HTML/Estruturas.txt b/HTML/Estruturas.txt new file mode 100644 index 0000000000000000000000000000000000000000..105b8f22f367aa2e903b25f9a60ff200d5f23e0d --- /dev/null +++ b/HTML/Estruturas.txt @@ -0,0 +1,8 @@ +//Arquivo que cont�m os defines e os registros +#include <stdio.h> +#include <time.h> +#include <stdlib.h> +#include <stdbool.h> +#include <sys/time.h> +#define TAM 20 //tamanho do vetor +#define NUMMAX 50 //constante que tem o m�ximo de valores diff --git "a/HTML/Fun\303\247\303\265es.txt" "b/HTML/Fun\303\247\303\265es.txt" new file mode 100644 index 0000000000000000000000000000000000000000..5768a8eba19ca25b5c6a746421b65aeb1c5a0fc8 --- /dev/null +++ "b/HTML/Fun\303\247\303\265es.txt" @@ -0,0 +1,14 @@ +//Cabe�alhos das Fun��es +void LerDados (int *Vetor); +void GeraVetor (int *Vetor); +void ImprimeVetor (int *Vetor); +void TempoSelectSort (int *Vetor); +void TempoBubbleSort (int *Vetor); +void TempoQuickSortRecursivo (int *Vetor); +void TempoQuickSortIterativo (int *Vetor); +void SelectSort (int *Vetor); +void BubbleSort (int *Vetor); +void QuickSortRecursivo (int Vetor[], int Esquerda, int Direita); +void QuickSortIterativo (int Vetor[], int Esquerda, int Direita); +void VerificaNumero (int *Vetor, int *Escolhidos); +void PesquisaBinaria (int *Vetor, int Elem); diff --git a/HTML/Main.txt b/HTML/Main.txt new file mode 100644 index 0000000000000000000000000000000000000000..4356e08479e01403fc5e95a8bcc23f79f7a24f04 --- /dev/null +++ b/HTML/Main.txt @@ -0,0 +1,55 @@ +#include "Estruturas.h" +#include "Fun��es.h" + + +int main () { + int Vetor[TAM], Escolhidos[4]; + int comando, Ordena; + for (;;) { + printf ("1 - Jogar\n2 - Comparar Algortimos\n"); + scanf ("%d", &comando); + switch (comando) { + case 1: + printf ("Digite 4 Valores de 1 a 50\n"); + LerDados (Escolhidos); + GeraVetor (Vetor); + //Sorteia o Algoritmo para Ordenar o Vetor + srand (time (NULL)); + Ordena = rand() % 4; + + switch (Ordena) { + + case 0: + printf ("O Vetor Foi Ordenado Pelo SelectSort\n"); + SelectSort (Vetor); + break; + + case 1: + printf ("O Vetor Foi Ordenado Pelo BubbleSort\n"); + BubbleSort (Vetor); + break; + + case 2: + printf ("O Vetor Foi Ordenado Pelo QuickSort Recursivo\n"); + QuickSortRecursivo (Vetor, 0, TAM); + break; + + case 3: + printf ("O Vetor Foi Ordenado Pelo QuickSort Iterativo\n"); + QuickSortIterativo (Vetor, 0, TAM); + break; + } + //Chama a Pesquisa + VerificaNumero (Vetor, Escolhidos); + ImprimeVetor (Vetor); + break; + + //Tempo de Execu��o dos programas + case 2: + TempoSelectSort (Vetor); + TempoBubbleSort (Vetor); + TempoQuickSortRecursivo (Vetor); + TempoQuickSortIterativo (Vetor); + } + } +} diff --git a/HTML/MedirTempo.txt b/HTML/MedirTempo.txt new file mode 100644 index 0000000000000000000000000000000000000000..026f56a6fc461641d68e75118189c1d605981877 --- /dev/null +++ b/HTML/MedirTempo.txt @@ -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/HTML/Ordena\303\247\303\243o.txt" "b/HTML/Ordena\303\247\303\243o.txt" new file mode 100644 index 0000000000000000000000000000000000000000..848cadc9a7fe15c915fb39a74b1da0643fd20a9a --- /dev/null +++ "b/HTML/Ordena\303\247\303\243o.txt" @@ -0,0 +1,132 @@ +//Arquivo com os Algoritmos de Ordena��o + +#include "Estruturas.h" +//Fun��o para trocar valores +void Troca (int *Vetor, int i, int j) { + int aux; + + aux = Vetor[i]; + Vetor [i] = Vetor[j]; + Vetor [j] = aux; +} + +//Algoritmo de Ordena��o do SelectSort +void SelectSort (int *Vetor) { + int i, j, menor; + + for (i = 0; i < TAM - 1; i++) { + menor = i; + for (j = i + 1; j < TAM; j++) + if (Vetor[menor] > Vetor[j]) + menor = j; + Troca (Vetor, i, menor); + } +} + +//Algoritmo de Ordena��o do BubbleSort +void BubbleSort (int *Vetor) { + bool trocou; + int i; + + trocou = true; + while (trocou) { + trocou = false; + for (i=0; i < TAM; i++) { + if (Vetor[i] > Vetor[i+1]) { + Troca(Vetor,i,i+1); + trocou = true; + } + } + } +} + +//Acha a posicao da Mediana +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; + +} + +//Particiona o QuickSort +int Particao (int *Vetor, int esq, int dir) { + int i,j,pivo,aux; + aux = Mediana(Vetor,esq,dir); + pivo = Vetor[aux]; + 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); + } + + Vetor[esq] = Vetor[j]; + Vetor[j] = pivo; + return j; +} + +//Algoritmo de Ordena��o do QuickSort com Recurs�o +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); + } +} + +//Algoritmo de Ordena��o do QuickSort Iterativo +void QuickSortIterativo (int Vetor[], int Esquerda, int Direita) { + int Posicao; + int Pilha[TAM]; + int top; + + top = -1; + //Empilha os Indices + Pilha[++top] = Esquerda; + Pilha[++top] = Direita; + while (top >= 0) { + //Desempilha os Indices + Direita = Pilha[top--]; + Esquerda = Pilha[top--]; + + Posicao = Particao(Vetor, Esquerda, Direita); + + if (Posicao-1 > Esquerda) { + //Empilha os Indices + Pilha[++top] = Esquerda; + Pilha[++top] = Posicao - 1; + } + if (Posicao+1 < Direita) { + //Empilha os Indices + Pilha[++top] = Posicao + 1; + Pilha[++top] = Direita; + } + } +} diff --git a/HTML/Pesquisa.txt b/HTML/Pesquisa.txt new file mode 100644 index 0000000000000000000000000000000000000000..531089a699acea104e23f38b7ff798ce4349e1c8 --- /dev/null +++ b/HTML/Pesquisa.txt @@ -0,0 +1,53 @@ +//Arquivo com os algoritmos de busca +#include "Estruturas.h" + +//Algoritmo de Pesquisa Binaria +int PesquisaBinaria (int *Vetor, int Elem) { + int meio, esquerda, direita; + + esquerda = 0; + direita = TAM - 1; + + do { + meio = (esquerda + direita)/2; + if (Elem > Vetor[meio]) + esquerda = meio + 1; + else + direita = meio - 1; + } while (Elem != Vetor[meio] && esquerda <= direita); + if (Elem == Vetor [meio]) + return (meio); + else + return -1; //return -1 pq o se o elemento estiver na primeira posi��o ir� retornar 0 (posi��o que ele se encontra no vetor) +} + +//Algoritmo de Pesquisa Sequencial +int PesquisaSequencial(int *Vetor, int Elem) { + int 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 +} + +//Chama as fun��es de Pesqusia para procurar o n�mero no vetor +void VerificaNumero (int *Vetor, int *Escolhidos) { + int i, acertos; + + acertos = 0; + //os dois primeiros numeros ser�o buscados pela PesquisaSequencial + for (i = 0; i < 2; i++) + if (PesquisaSequencial (Vetor, Escolhidos[i]) != -1) { + printf ("Acertou o Numero %d, Parab�ns\n", Escolhidos[i]); + acertos++; + } + //os dois ultimos numeros ser�o buscados pela PesquisaBinaria + for (i = i; i < 4; i++) + if (PesquisaBinaria (Vetor, Escolhidos[i]) != -1) { + printf ("Acertou o Numero %d, Parab�ns\n", Escolhidos[i]); + acertos++; + } + printf ("O Total de Acertos foi de: %d\n", acertos); +} diff --git a/HTML/Vetor.txt b/HTML/Vetor.txt new file mode 100644 index 0000000000000000000000000000000000000000..ffc5ede68844c1ea696edb34938c0d934bd5cd64 --- /dev/null +++ b/HTML/Vetor.txt @@ -0,0 +1,33 @@ +#include "Estruturas.h" + +//L� os 4 n�meros que o usuario entra +void LerDados (int *Vetor) { + int i; + printf ("Digite 4 n�meros: "); + for (i = 0; i < 4; i++) + scanf ("%d", &Vetor[i]); +} + + +//Fun��o que gera valores aleatorios para o vetor +void GeraVetor (int *Vetor) { + int i; + + srand (time(NULL)); + for (i=0; i < TAM; i++) + Vetor[i] = (rand () % NUMMAX) + 1; +} + +//Fun��o que imprime o vetor +void ImprimeVetor (int *Vetor) { + int i; + + printf ("Pos: "); + for (i=0; i < TAM; i++) + printf ("\t%d", i); + printf ("\n"); + printf ("Num: "); + for (i=0; i < TAM; i++) + printf ("\t%d", Vetor[i]); + printf ("\n"); +} diff --git a/HTML/index.html b/HTML/index.html index b62b57116b03a1ba468172ca40e7e6c4444a26ad..4710c66b8984948c2f149756b8b5b4f776da20f6 100644 --- a/HTML/index.html +++ b/HTML/index.html @@ -9,16 +9,19 @@ Fernando Claudecir Erd (fce15)</p> Gabriel Ruschel Castanhel (grc15) </p> <h3>Arquivos do Programa</h3> - <h5><a href="Estruturas.h.txt">Estruturas.h</a></h5> - <h5><a href="Ordena��o.c.txt">Ordena��o.c</a></h5> - <h5><a href="Pesquisa.c.txt">Pesquisa.c</a></h5> - <h5><a href="Vetor.c.txt">Vetor.c</a></h5> - <h5><a href="Main.c.txt">Main.c</a></h5> + <h5><a href="Estruturas.txt">Estruturas.h</a></h5> + <h5><a href="Fun��es.txt">Fun��es.h</a></h5> + <h5><a href="Ordena��o.txt">Ordena��o.c</a></h5> + <h5><a href="MedirTempo.txt">MedirTempo.c</a></h5> + <h5><a href="Pesquisa.txt">Pesquisa.c</a></h5> + <h5><a href="Vetor.txt">Vetor.c</a></h5> + <h5><a href="Main.txt">Main.c</a></h5> <h5><a href="makefile.txt">Comandos de compila��o</a></h5> <h3>Relat�rio</h3> <h5><a href="Relatorio.html">Relat�rio</a></h5> <h3>Logs</h3> - <h5><a href="log.txt">Logs</a></h5> + <h5><a href="logMega.txt">Log Mega Quadra</a></h5> + <h5><a href="logCompare.txt">Log Compara��o</a></h5> </body> </html> diff --git a/HTML/logCompare.txt b/HTML/logCompare.txt new file mode 100644 index 0000000000000000000000000000000000000000..f47cd07bed0ac33404713be69ccb74c3307565cc --- /dev/null +++ b/HTML/logCompare.txt @@ -0,0 +1,51 @@ +//ATEN��O: NO LOG DAS COMPARA��ES FOI ALTERADO O TAMANHO DO VETOR NO ARQUIVO ESTRUTURAS.H (#DEFINE TAM) PARA QUE SE POSSA FAZER UMA ANALISE MAIS AMPLA DE COMO O TEMPO DA ORDENA��O CRESCE DE ACORDO COM O TAMANHO DO VETOR + +//No menu principal sempre foi escolhida a op��o 2 +1 - Jogar +2 - Comparar Algortimos + +//Definindo #define TAM 10 - Tamanho do Vetor ser� 10 +O SelectSort Demorou 28 Centesimos +O BubbleSort Demorou 31 Centesimos +O QuickSort Recursivo Demorou 28 Centesimos +O QuickSort Iterativo Demorou 27 Centesimos + + +//Definindo #define TAM 25 - Tamanho do Vetor ser� 25 +O SelectSort Demorou 51 Centesimos +O BubbleSort Demorou 73 Centesimos +O QuickSort Recursivo Demorou 42 Centesimos +O QuickSort Iterativo Demorou 41 Centesimos + + +//Definindo #define TAM 50 - Tamanho do Vetor ser� 50 +O SelectSort Demorou 109 Centesimos +O BubbleSort Demorou 249 Centesimos +O QuickSort Recursivo Demorou 79 Centesimos +O QuickSort Iterativo Demorou 77 Centesimos + +//Definindo #define TAM 75 - Tamanho do Vetor ser� 75 +O SelectSort Demorou 192 Centesimos +O BubbleSort Demorou 484 Centesimos +O QuickSort Recursivo Demorou 117 Centesimos +O QuickSort Iterativo Demorou 107 Centesimos + +//Definindo #define TAM 100 - Tamanho do Vetor ser� 100 +O SelectSort Demorou 296 Centesimos +O BubbleSort Demorou 824 Centesimos +O QuickSort Recursivo Demorou 154 Centesimos +O QuickSort Iterativo Demorou 139 Centesimos + +//Definindo #define TAM 500 - Tamanho do Vetor ser� 500 +O SelectSort Demorou 5370 Centesimos +O BubbleSort Demorou 23400 Centesimos +O QuickSort Recursivo Demorou 853 Centesimos +O QuickSort Iterativo Demorou 822 Centesimos + +//Definindo #define TAM 1000 - Tamanho do Vetor ser� 1000 +O SelectSort Demorou 20553 Centesimos //20 segundos +O BubbleSort Demorou 93153 Centesimos //93 segundos +O QuickSort Recursivo Demorou 1830 Centesimos +O QuickSort Iterativo Demorou 1782 Centesimos + + diff --git a/HTML/logMega.txt b/HTML/logMega.txt new file mode 100644 index 0000000000000000000000000000000000000000..082893a36786e42a8495b63640384d0a18ece1da --- /dev/null +++ b/HTML/logMega.txt @@ -0,0 +1,53 @@ +1 - Jogar +2 - Comparar Algortimos +Entrada = 1 + +Digite 4 Valores de 1 a 50 +Digite 4 n�meros: 1 3 43 23 + +O Vetor Foi Ordenado Pelo SelectSort +Acertou o Numero 3, Parab�ns +Acertou o Numero 23, Parab�ns +O Total de Acertos foi de: 2 +Pos: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 +Num: 2 3 3 4 12 14 17 20 21 23 31 33 33 35 36 40 41 41 46 49 + +1 - Jogar +2 - Comparar Algortimos +Entrada = 1 + +Digite 4 Valores de 1 a 50 +Digite 4 n�meros: 7 11 25 40 + +O Vetor Foi Ordenado Pelo QuickSort Recursivo +Acertou o Numero 11, Parab�ns +O Total de Acertos foi de: 1 +Pos: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 +Num: 10 11 13 13 13 15 15 17 18 20 20 26 26 30 31 31 46 47 47 49 + +1 - Jogar +2 - Comparar Algortimos +Entrada = 1 + +Digite 4 Valores de 1 a 50 +Digite 4 n�meros: 10 23 35 38 + +O Vetor Foi Ordenado Pelo QuickSort Iterativo +O Total de Acertos foi de: 0 +Pos: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 +Num: 6 6 7 7 8 17 18 18 20 25 27 33 42 42 42 42 48 48 50 50 + +1 - Jogar +2 - Comparar Algortimos +Entrada = 1 + +Digite 4 Valores de 1 a 50 +Digite 4 n�meros: 1 32 2 4 + +O Vetor Foi Ordenado Pelo BubbleSort +Acertou o Numero 1, Parab�ns +Acertou o Numero 2, Parab�ns +Acertou o Numero 4, Parab�ns +O Total de Acertos foi de: 3 +Pos: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 +Num: 1 1 2 4 9 11 11 12 13 25 31 38 40 41 44 45 47 49 49 49 diff --git a/HTML/makefile.txt b/HTML/makefile.txt new file mode 100644 index 0000000000000000000000000000000000000000..9afeaa32aa603ec26fa5e2efc5349fbe5f9b27db --- /dev/null +++ b/HTML/makefile.txt @@ -0,0 +1,9 @@ +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 MedirTempo.o -o Loteria -g + rm *.o +