直接插入排序算法
#include <stdio.h>
#include <stdlib.h>
void insert_sort(int a[], int n){
int i,j,temp;
for(i=1;i<n;i++){
j = i;
temp = a[i];
while(j>0 && a[j-1]>temp){
a[j] = a[j-1];
j--;
}
a[j] = temp;
}
}
int main(){
int a[5] = {2,1,0,4,5};
insert_sort(a,5);
for(int i=0; i<5; i++){
printf("%d ", a[i]);
}
return 0;
}