插入排序
#include <stdio.h>
#include<string.h>
#include<stdlib.h>
int main(int argc, const char *argv[])
{int a[]={41,50,66,38,32,49,18};int n=sizeof(a)/sizeof(a[0]);int i,j,t;for(i=1;i<n;i++){int t=a[i];for(j=i-1;j>=0;j--){if(t<a[j]){a[j+1]=a[j];}elsebreak;}a[j+1]=t;}for(i=0;i<n;i++){printf("%-4d",a[i]);}puts("");return 0;
}
ubuntu@ubuntu:day5$ gcc homework.c
ubuntu@ubuntu:day5$ ./a.out
18 32 38 41 49 50 66
ubuntu@ubuntu:day5$