插入排序


#include
#include
typedef int ElementType;

/* 插入排序 */
void InsertionSort( ElementType A[], int N )
{
	int j, P;
	ElementType Tmp;
	for( P = 1; P < N; P++ )
	{
		Tmp = A[ P ];
		for( j = P; j > 0 && A[ j - 1 ] > Tmp; j-- )
			A[ j ] = A[ j - 1 ];
		A[ j ] = Tmp;
	}
}

int main()
{
	int A[10] = {5,15,748,8,14,63,19,20,72,62};
	int i;
	InsertionSort( A, 10 );
	for( i = 0; i < 10; i++ )
	{
		printf( "%d ", A[ i ] );
	}
}

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注