#include<stdio.h> #include<string.h> #define MAX 200 int R[MAX]; //直接插入排序算法 void Insert_Order(int n) { int i,j; for(i=2;i<=n;i++) { if(R[i]<R[i-1]) { R[0]=R[i]; j=i-1; do{ R[j+1]=R[j]; j--; }while(R[0]<R[j]); } R[j+1]=R[0]; } } int main() { int n; int i; printf("Please input n under %d: ",MAX); scanf("%d",&n); if(n<1||n>MAX) { printf("Please input n above 1 and below %d ",MAX); return 0; } printf("Please input the array one by one:"); for(i=1;i<=n;i++) { scanf("%d",&R[i]); } printf("The array you input is :"); for(i=1;i<=n;i++) { printf("%d ",R[i]); } Insert_Order(n); printf("The array after order is:"); for(i=1;i<=n;i++) { printf("%d ",R[i]); } return 0; }