插入排序算法代码示例:
#include "stdafx.h"
int A[10] = {3,2,6,4,1,5,7,9,8,10};
void Insert_Sort(int *A, int length)
{
for(int j = 1; j < length; j++)
{
int key = A[j];
int i = j - 1;
while(i >= 0 && A[i] > key)
{
A[i+1] = A[i];
i = i - 1;
}
A[i+1] = key;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
Insert_Sort(A,10);
for(int i = 0; i < 10; i++)
{
printf("%d ", A[i]);
}
return 0;
}