数据结构之 直接插入排序

#include "stdafx.h"


void InsertSort(int R[],int n)
{
	int i,j;
	int temp;
	for(i=2;i<=n;i++)
	{
		temp=R[i];
		j=i-1;
		while(temp<R[j]&&j>=1)
		{
			R[j+1]=R[j];
			--j;
		}
		R[j+1]=temp;
	}
}
void show(int a[],int n)
{
	for(int i=1;i<=n;i++)
		printf("%d ",a[i]);
	printf("
");
}
int _tmain(int argc, _TCHAR* argv[])
{
	int A[]={0,1,5,3,6,8,2,9,7,0,4};//0 那个位置不存数据
	show(A,10);
	InsertSort(A,10);
	show(A,10);
	return 0;
}


原文地址:https://www.cnblogs.com/phisy/p/3363627.html