Skip to content
Snippets Groups Projects
Commit 820c6fe8 authored by Fernando Erd's avatar Fernando Erd :ok_hand:
Browse files

Arrumando Pesquisa Sequencial

parent e32ac312
No related branches found
No related tags found
No related merge requests found
......@@ -4,5 +4,5 @@
#include <stdlib.h>
#include <stdbool.h>
#include <sys/time.h>
#define TAM 15 //tamanho do vetor
#define TAM 100 //tamanho do vetor
#define NUMMAX 50 //constante que tem o máximo de valores
No preview for this file type
#include "Estruturas.h"
#include "Funções.h"
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);
}
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);
}
int main () {
int Vetor[TAM], Escolhidos[4];
struct timeval inicio, final;
int tmili, i, comando;
int comando;
printf ("1 Para Jogar e 2 Para Comparar Algoritmos\n");
scanf ("%d", &comando);
......@@ -17,13 +44,7 @@ int main () {
ImprimeVetor (Vetor);
break;
case 2:
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);
TempoSelectSort (Vetor);
TempoBubbleSort (Vetor);
}
}
......@@ -23,10 +23,11 @@ int PesquisaBinaria (int *Vetor, int Elem) {
int PesquisaSequencial(int *Vetor, int Elem) {
int i;
Vetor[0] = Elem;
for (i=TAM-1; i>=0; 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
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment