插入排序
#include<stdio.h>
#define N 10
void InsertionSort(int arr[])//插入排序
{
int i, j, tmp;
for (i = 1; i < N; i++) {
if (arr[i] < arr[i-1]) {
tmp = arr[i];
for (j = i - 1; j >= 0 && arr[j] > tmp; j--) {
arr[j+1] = arr[j];
}
arr[j+1] = tmp;
}
}
}
int main()
{
int arr[N]={6,5,8,1,7,15,11,19,21,-9},i;
InsertionSort(arr);
for(i=0;i<N;i++){
printf("%d ",arr[i]);
}
return 0;
}