Chce zmierzyc czas działania insertion sort jednak program wypisuje mi 0.00000. Ma ktoś pojęcie dlaczego ?
Oto Kod
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <dos.h>
#include <time.h>
#include <windows.h>
#define NUMBEROFROWS 100
#define NUMBEROFEXP 10
void bubblesort(int[]);
void insertsor(int[]);
void selectionsort(int []);
void generujlos(int [],int);
int main(int argc, char *argv[])
{
int size;
int exp = 10;
for(exp; exp <= 16;exp++)
{
size = pow(2,exp);
int tab[size];
generujlos(tab,size);
printf("************************** %d \n", exp);
}
system("PAUSE");
return 0;
}
void selectionsort(int tab[])
{
int min;
int i =0;
for(i;i< NUMBEROFROWS-1;i++)
{
min = tab[i];
int j=i+1;
for(j;j< NUMBEROFROWS;j++)
{
if(min>tab[j])
{
min = tab[j];
}
}
int temp = tab[i];
tab[i] = min;
tab[j] = temp;
}
}
void generujlos(int tab[],int size)
{
FILE *f;
srand(time(NULL));
int i;
f = fopen("c.txt", "w");
if (f == NULL) {
perror("Nie udalo sie otworzyc pliku 'c.dat' do zapisu");
return ;
}
fprintf(f, "# file-output.c\n");
for(i=0;i<size ;i++)
{
tab[i] = rand()% size;
printf("%d \n", tab[i]);
fprintf(f, "%d\n",tab[i]);
}
fflush(f);
fclose(f);
clock_t start = clock();
selectionsort(tab);
printf ( "%f\n", ( (double)clock() - start ) / CLOCKS_PER_SEC );
}
Shalom