#include<stdio.h>
//基本操作位讲一个记录插入到已经排好序的有序表中
void InsertSort(int a[],int n){
int i,j,temp;
for(i = 1;i<n;i++){
if(a[i] < a[i-1]){ //前后比,条件成立,存入temp容器
temp = a[i];
for(j = i-1;a[j]>temp;j--){ //条件成立遍历移动,找要插入位置
a[j+1] = a[j];
}
a[j+1] = temp; //将temp存入
}
}
}
int main(void){
int a[8] = {3,2,5,8,4,7,6,9};
InsertSort(a,8);
for(int i = 0;i < 8;i++){
printf("%d\t",a[i]);
}
printf("\n");
return 0;
}