diff --git a/Arquivos/Estruturas.h b/Arquivos/Estruturas.h index 326d51f5aba656d5047c692f94c7880f8b67d769..6ac3e15948f8d44dc7a04633e00e05354aede926 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 100 //tamanho do vetor -#define NUMMAX 10 //constante que tem o máximo de valores +#define TAM 10 //tamanho do vetor +#define NUMMAX 5 //constante que tem o máximo de valores diff --git a/Arquivos/Loteria b/Arquivos/Loteria index 08a9e5928885a26d371d38c973e4ee089c824de9..de5997e00e653a3e13ffce9849ebf96a0c075f61 100755 Binary files a/Arquivos/Loteria and b/Arquivos/Loteria differ diff --git a/Arquivos/Main.c b/Arquivos/Main.c index 86042194d836d10464530ea9a8c5598c692a47cb..0f7aa867d3ce2784bad897cdbab95f3de8a2080f 100644 --- a/Arquivos/Main.c +++ b/Arquivos/Main.c @@ -59,7 +59,7 @@ void TempoQuickSortIterativo (int *Vetor) { int main () { int Vetor[TAM], Escolhidos[4]; - int comando; + int comando, Ordena; printf ("1 Para Jogar e 2 Para Comparar Algoritmos\n"); scanf ("%d", &comando); @@ -67,7 +67,26 @@ int main () { case 1: LerDados (Escolhidos); GeraVetor (Vetor); + srand (time (NULL)); + Ordena = rand() % 3; + 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; + } VerificaNumero (Vetor, Escolhidos); ImprimeVetor (Vetor); break; diff --git "a/Arquivos/Ordena\303\247\303\243o.c" "b/Arquivos/Ordena\303\247\303\243o.c" index ea8754900cc2725968071b8162ebadb2560b69b3..515df4b64415c10fdcc84fc86df205a102896a00 100644 --- "a/Arquivos/Ordena\303\247\303\243o.c" +++ "b/Arquivos/Ordena\303\247\303\243o.c" @@ -38,21 +38,53 @@ void BubbleSort (int *Vetor) { } } -int Particao (int Vetor[], int Esquerda, int Direita) { - int Pivo, i, j; - - Pivo = Vetor[Direita]; - i = (Esquerda - 1); - for (j = Esquerda; j <= Direita- 1; j++) - { - if (Vetor[j] <= Pivo) - { - i++; - Troca (Vetor, i, j); - } - } - Troca (Vetor,i + 1, Direita); - return (i+1); +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]; + 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; } void QuickSortRecursivo (int Vetor[], int Esquerda, int Direita) {