diff --git a/t1/main.c b/t1/main.c index a7d6169b75ecf1fe42d48d1f1faf98fefd999e7c..2b690b6f782118f312ff3f3717b281d3615b6549 100644 --- a/t1/main.c +++ b/t1/main.c @@ -4,22 +4,25 @@ #include "ordenacao.h" -void imprimeVetor(int v[], int tam) { +void imprimeVetor(int v[], int tamV) { printf("\n["); - for (int i=0;i<20;i++) { + for (int i=0;i<10;i++) { printf("%d ", v[i]); } - printf("...%d]\n", v[tam-1]); + if (tamV > 10) + printf("...%d]\n", v[tamV-1]); + else + printf("]\n"); } -void geraVetorAleatorio(int v[], int tam) { - for (int i=0;i<tam;i++) { - v[i] = rand() % 100 + 1; +void geraVetorAleatorio(int v[], int tamV) { + for (int i=0;i<tamV;i++) { + v[i] = rand() % 10000 + 1; } } -void geraVetor(int v[], int tam) { - for (int i=0;i<tam;i++) { +void geraVetor(int v[], int tamV) { + for (int i=0;i<tamV;i++) { v[i] = i; } } @@ -47,7 +50,7 @@ int main(){ printf("----------------------------------------------------\n"); - printf("Comecando os teste com os vetores de busca...\n"); + printf("Comecando os teste com os algoritmos de busca...\n"); printf("----------------------------------------------------\n"); printf("\n--->BUSCA SEQUENCIAL\n"); @@ -129,10 +132,10 @@ int main(){ printf("\n----------------------------------------------------\n"); - printf("Comecando os teste com os vetores de ordenacao...\n"); + printf("Comecando os teste com os algoritmos de ordenacao...\n"); printf("----------------------------------------------------\n"); - printf("\n--->INSERTION SORT\n"); + printf("\n~~~>INSERTION SORT<~~~\n"); //TESTE 1 geraVetorAleatorio(vetor,tam); @@ -181,15 +184,48 @@ int main(){ imprimeVetor(vetor, 50*tam); printf("(Nº de comp: %d | Tempo total: %f)\n",numComp, total); + //TESTE 5 + geraVetorAleatorio(vetor,100*tam); + printf("\nOrdenando um vetor tam = 1000"); + imprimeVetor(vetor, 100*tam); + start = clock();//start recebe o "ciclo" corrente + numComp = insertionSort(vetor,100*tam); + end = clock();//end recebe o "ciclo" corrente + total = ((double)end - start)/CLOCKS_PER_SEC; + imprimeVetor(vetor, 100*tam); + printf("(Nº de comp: %d | Tempo total: %f)\n",numComp, total); + + //TESTE 6 + geraVetorAleatorio(vetor,500*tam); + printf("\nOrdenando um vetor tam = 5000"); + imprimeVetor(vetor, 500*tam); + start = clock();//start recebe o "ciclo" corrente + numComp = insertionSort(vetor,500*tam); + end = clock();//end recebe o "ciclo" corrente + total = ((double)end - start)/CLOCKS_PER_SEC; + imprimeVetor(vetor, 500*tam); + printf("(Nº de comp: %d | Tempo total: %f)\n",numComp, total); + + //TESTE 7 + geraVetorAleatorio(vetor,1000*tam); + printf("\nOrdenando um vetor tam = 10000"); + imprimeVetor(vetor, 1000*tam); + start = clock();//start recebe o "ciclo" corrente + numComp = insertionSort(vetor,1000*tam); + end = clock();//end recebe o "ciclo" corrente + total = ((double)end - start)/CLOCKS_PER_SEC; + imprimeVetor(vetor, 1000*tam); + printf("(Nº de comp: %d | Tempo total: %f)\n",numComp, total); + printf("\n"); - printf("\n--->SELECTION SORT\n"); + printf("\n~~~>SELECTION SORT<~~~\n"); //TESTE 1 geraVetorAleatorio(vetor,tam); printf("\nOrdenando um vetor tam = 10"); - imprimeVetor(vetor, tam); + imprimeVetor(vetor,tam); start = clock();//start recebe o "ciclo" corrente numComp = selectionSort(vetor,tam); end = clock();//end recebe o "ciclo" corrente @@ -232,9 +268,42 @@ int main(){ imprimeVetor(vetor, 50*tam); printf("(Nº de comp: %d | Tempo total: %f)\n",numComp, total); + //TESTE 5 + geraVetorAleatorio(vetor,100*tam); + printf("\nOrdenando um vetor tam = 1000"); + imprimeVetor(vetor, 100*tam); + start = clock();//start recebe o "ciclo" corrente + numComp = selectionSort(vetor,100*tam); + end = clock();//end recebe o "ciclo" corrente + total = ((double)end - start)/CLOCKS_PER_SEC; + imprimeVetor(vetor, 100*tam); + printf("(Nº de comp: %d | Tempo total: %f)\n",numComp, total); + + //TESTE 6 + geraVetorAleatorio(vetor,500*tam); + printf("\nOrdenando um vetor tam = 5000"); + imprimeVetor(vetor, 500*tam); + start = clock();//start recebe o "ciclo" corrente + numComp = selectionSort(vetor,500*tam); + end = clock();//end recebe o "ciclo" corrente + total = ((double)end - start)/CLOCKS_PER_SEC; + imprimeVetor(vetor, 500*tam); + printf("(Nº de comp: %d | Tempo total: %f)\n",numComp, total); + + //TESTE 7 + geraVetorAleatorio(vetor,1000*tam); + printf("\nOrdenando um vetor tam = 10000"); + imprimeVetor(vetor, 1000*tam); + start = clock();//start recebe o "ciclo" corrente + numComp = selectionSort(vetor,1000*tam); + end = clock();//end recebe o "ciclo" corrente + total = ((double)end - start)/CLOCKS_PER_SEC; + imprimeVetor(vetor, 1000*tam); + printf("(Nº de comp: %d | Tempo total: %f)\n",numComp, total); + printf("\n"); - printf("\n--->MERGE SORT\n"); + printf("\n~~~>MERGE SORT<~~~\n"); //TESTE 1 geraVetorAleatorio(vetor,tam); @@ -281,10 +350,43 @@ int main(){ total = ((double)end - start)/CLOCKS_PER_SEC; imprimeVetor(vetor, 50*tam); printf("(Nº de comp: %d | Tempo total: %f)\n",numComp, total); + + //TESTE 5 + geraVetorAleatorio(vetor,100*tam); + printf("\nOrdenando um vetor tam = 1000"); + imprimeVetor(vetor, 100*tam); + start = clock();//start recebe o "ciclo" corrente + numComp = mergeSort(vetor,100*tam); + end = clock();//end recebe o "ciclo" corrente + total = ((double)end - start)/CLOCKS_PER_SEC; + imprimeVetor(vetor, 100*tam); + printf("(Nº de comp: %d | Tempo total: %f)\n",numComp, total); + + //TESTE 6 + geraVetorAleatorio(vetor,500*tam); + printf("\nOrdenando um vetor tam = 5000"); + imprimeVetor(vetor, 500*tam); + start = clock();//start recebe o "ciclo" corrente + numComp = mergeSort(vetor,500*tam); + end = clock();//end recebe o "ciclo" corrente + total = ((double)end - start)/CLOCKS_PER_SEC; + imprimeVetor(vetor, 500*tam); + printf("(Nº de comp: %d | Tempo total: %f)\n",numComp, total); + + //TESTE 7 + geraVetorAleatorio(vetor,1000*tam); + printf("\nOrdenando um vetor tam = 10000"); + imprimeVetor(vetor, 1000*tam); + start = clock();//start recebe o "ciclo" corrente + numComp = mergeSort(vetor,1000*tam); + end = clock();//end recebe o "ciclo" corrente + total = ((double)end - start)/CLOCKS_PER_SEC; + imprimeVetor(vetor, 1000*tam); + printf("(Nº de comp: %d | Tempo total: %f)\n",numComp, total); printf("\n"); - printf("\n--->QUICK SORT\n"); + printf("\n~~~>QUICK SORT<~~~\n"); //TESTE 1 geraVetorAleatorio(vetor, tam); @@ -331,6 +433,39 @@ int main(){ total = ((double)end - start)/CLOCKS_PER_SEC; imprimeVetor(vetor, 50*tam); printf("(Nº de comp: %d | Tempo total: %f)\n",numComp, total); + + //TESTE 5 + geraVetorAleatorio(vetor,100*tam); + printf("\nOrdenando um vetor tam = 1000"); + imprimeVetor(vetor, 100*tam); + start = clock();//start recebe o "ciclo" corrente + numComp = quickSort(vetor,100*tam); + end = clock();//end recebe o "ciclo" corrente + total = ((double)end - start)/CLOCKS_PER_SEC; + imprimeVetor(vetor, 100*tam); + printf("(Nº de comp: %d | Tempo total: %f)\n",numComp, total); + + //TESTE 6 + geraVetorAleatorio(vetor,500*tam); + printf("\nOrdenando um vetor tam = 5000"); + imprimeVetor(vetor, 500*tam); + start = clock();//start recebe o "ciclo" corrente + numComp = quickSort(vetor,500*tam); + end = clock();//end recebe o "ciclo" corrente + total = ((double)end - start)/CLOCKS_PER_SEC; + imprimeVetor(vetor, 500*tam); + printf("(Nº de comp: %d | Tempo total: %f)\n",numComp, total); + + //TESTE 7 + geraVetorAleatorio(vetor,1000*tam); + printf("\nOrdenando um vetor tam = 10000"); + imprimeVetor(vetor, 1000*tam); + start = clock();//start recebe o "ciclo" corrente + numComp = quickSort(vetor,1000*tam); + end = clock();//end recebe o "ciclo" corrente + total = ((double)end - start)/CLOCKS_PER_SEC; + imprimeVetor(vetor, 1000*tam); + printf("(Nº de comp: %d | Tempo total: %f)\n",numComp, total); printf("\n"); diff --git a/t1/main.o b/t1/main.o index 74333eb9a7492ad220eaee0324cafd606e7e546b..8de90053bd6e4e79e1a025d93d71717eec6ef36b 100644 Binary files a/t1/main.o and b/t1/main.o differ diff --git a/t1/trab b/t1/trab index 2c2f2482cccf472f2cd9ee7474170f07893d1485..63926ac198eb4def9de91b172ad7ce64079381f8 100755 Binary files a/t1/trab and b/t1/trab differ