#include "stdlib.h"
#include "stdio.h"
#include "time.h"
void insertion_sort(int a[], int length)
{
int i = 0;
int j = 0;
int n = length;
int temp = 0;
for(j=1; j {
temp = a[j];
i = j-1;
while(i>=0 && a[i] < temp)
{
a[i+1] = a[i];
i = i-1;
}
a[i+1] = temp;
}
}
int main(int argc, char* argv[])
{
int i=0;
int *a = NULL;
FILE * fp;
fp=fopen("data.txt","a+");
a = (int*)malloc(1000*sizeof(int));
srand((unsigned)time(0));
for(i=0;i<1000;i++)
{
a[i]=(int)rand();
}
insertion_sort(a , 1000);
for(i=0; i<1000; i++)
{
fprintf(fp,"%d\t", a[i]);
}
free(a);
fclose(fp);
return 0;
}
阅读(960) | 评论(0) | 转发(0) |