Advertisement
vittooh

Untitled

Sep 9th, 2015
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.03 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include<time.h>
  4.  
  5.  
  6. void ordena(int *a,int n){
  7.     int i,j,min;
  8.     int t;
  9.     for (i = 0; i <= n; i++) {
  10.     min = i;
  11.     for (j = i+1; j <=n; j++)
  12.     if (a[j] < a[min]) min = j;
  13.     t = a[min]; a[min] = a[i]; a[i] = t;
  14.     }
  15. }
  16.  
  17.  
  18. int main()
  19. {
  20.     int h,k;
  21.     FILE* saida;
  22.     saida=fopen("/home/vhugo/Área de trabalho/novo.txt","w");
  23.     if(saida==NULL){
  24.         printf("Deu merda");
  25.         return 0;
  26.     }
  27.     for(h=1;h<=10000;h++) {
  28.         fprintf(saida,"case: %d\n",h);
  29.         for (k = 1; k <= 1000; k++) {
  30.             clock_t t_i, t_f;
  31.             double tempo_total;
  32.  
  33.             int *vet;
  34.             int i;
  35.             vet = ( int *) malloc(sizeof(int) * h);
  36.  
  37.             for (i = 0; i < h; i++) {
  38.                 vet[i] = rand() % 100;
  39.             }
  40.  
  41.             t_i = clock();
  42.  
  43.  
  44.             ordena(vet, h);
  45.  
  46.             t_f = clock();
  47.             tempo_total = t_f - t_i;
  48.             fprintf(saida, "%lf\n", tempo_total);
  49.         }
  50.     }
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement