码迷,mamicode.com
首页 > 其他好文 > 详细

CLRS:Insert sort in in c

时间:2016-05-03 21:53:08      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#define ARRAY_SIZE 1000
int buf[ARRAY_SIZE];
int main()
{
int i,j,n;
srand((unsigned int)time(0));
memset(buf,0,sizeof(buf[0]));
while(scanf("%d",&n)!=EOF)
{
for(i=1;i<=n;i++)buf[i]=rand()%100;//creat th data storage in buf
for(i=1;i<=n;i++)printf("%d ",buf[i]);//before sort
printf("\nAffter sort:\n");
for(j=2;j<=n;j++)
{
buf[0]=buf[j];
for(i=j-1;i>0&&buf[i]>buf[0];i--)buf[i+1]=buf[i];
buf[i+1]=buf[0];
}
for(i=1;i<=n;i++)printf("%d ",buf[i]);//after sort
printf("\n");
}

}

CLRS:Insert sort in in c

标签:

原文地址:http://www.cnblogs.com/zeroArn/p/5456531.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!