#include <stdio.h>
#include <time.h>
#define MAX_SIZE 5001
#define SWAP(x,y,t) ((t)=(x), (x) = (y), (y) = (t))
void sort(int list[], int n)
{
int i, j, min, temp;
for(i=0; i<n-1; i++){
min = i;
for(i=0; i<n-1; i++){
min=i;
for(j=i+1; j<n; j++)
if(list[j] <list[min])
min = j;
SWAP(list[i], list[min],temp);
}
}
}
void main()
{
int i,n,step = 500;
int a[MAX_SIZE];
double duration;
for(i=1; i<=10; i++)
{
a[i] = rand();
}
printf(" n time\n");
for(n=0; n<=5000; n+=step)
{
clock_t start = clock();
long repetition= 0;
do
{
repetition++;
for(i=0; i<n; i++)
a[i] =n-i;
sort(a, n);
}while(clock() -start <1000);
duration = ((double) (clock() -start))/CLOCKS_PER_SEC;
duration/=repetition;
printf("%6d %f\n", n,duration);
if(n==1000) step =1000;
}
}
'IT' 카테고리의 다른 글
그냥 인설션소트 (0) | 2014.06.09 |
---|---|
인설션 소트 시간 측정 (0) | 2014.06.09 |
런이라는 단어가 있는걸로 봐서 위너트리 (0) | 2014.06.09 |
인설션소트 (0) | 2014.06.09 |
후위식변환3 (0) | 2014.06.09 |