- #include <stdio.h>
- void insertsort(int a[],int n)
- {
- int i,j;
- for(i=2;i<=n;++i)
- {
- if(a[i]<a[i-1])
- {
- a[0]=a[i];
- for(j=i-1;a[0]<a[j];--j)
- a[j+1]=a[j];
- a[j+1]=a[0];
- }
- }
- }
- void Display(int a[],int n)
- {
- int i;
- for(i=1;i<=n;++i)
- printf("%d ",a[i]);
- printf("\\n");
- }
- int main(void)
- {
- int i,n;
- int a[100];
- printf("Please input the total num:\\n");
- scanf("%d",&n);
- printf("Pleaase input the elem:\\n");
- for(i=1;i<=n;++i)
- {
- scanf("%d",&a[i]);
- }
- insertsort(a,n);
- for(i=1;i<=n;++i)
- printf("%d ",a[i]);
- printf("\\n");
- return 0;
- }
- //该片段来自于http://www.codesnippet.cn/detail/2711201411094.html
来源: http://www.codesnippet.cn/detail/2711201411094.html