Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include "ordenation.h"
- int main(){
- int size, *array, num, busca;
- double time_spent;
- clock_t begin, end;
- srand(time(NULL));
- printf("Qual o tamanho do vetor que deseja ordenar? ");
- scanf("%d", &size);
- printf("Qual busca deseja fazer: sequencial[0] ou binaria[1]? ");
- scanf("%d", &busca);
- array = (int *) malloc(sizeof(int)*size);
- for(int i = 0; i < size; i++){
- array[i] = rand()%size; //numeros de zero até size
- }
- //clock no inicio
- begin = clock();
- //ordena
- insertion_sort(array, size);
- //clock no final
- end = clock();
- time_spent = (double) (end - begin)/CLOCKS_PER_SEC;
- printf("O tempo para a ordenacao foi de %f", time_spent);
- num = (rand()*100)%(size*2);
- if(busca == 0){
- begin = clock();
- int position = linear_search(array, size, 0, num);
- end = clock();
- time_spent = (double) (end - begin)/CLOCKS_PER_SEC;
- printf("\nO tempo para a busca sequencial foi de %f", time_spent);
- }
- else if(busca == 1){
- begin = clock();
- int position = binary_search(array, size, num);
- end = clock();
- time_spent = (double) (end - begin)/CLOCKS_PER_SEC;
- printf("\nO tempo para a busca binaria foi de %f", time_spent);
- }
- else
- printf("Opcao de busca invalida.");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement