插入排序

#include<iostream>
using namespace std;
#define SIZE   10
void Insert_Sort(int array[]);
void Show_Array(int array[]);
void main()
{
	int array[SIZE]={12,4512,65,45,21,76,122,67,32,9};
	Insert_Sort(array);
	Show_Array(array);
}

void Insert_Sort(int array[])
{
	int i,j;
	int temp;
	for (i=1;i<SIZE;i++)   //第一个数已有序
	{
		temp=array[i];   
		j=i-1;
		for (j;j>=0 && array[j]>temp;j--)  //在有序序列中找比temp大的数,并将其顺序后移
		{
			array[j+1]=array[j];
		
		}
		array[j+1]=temp;

	}
}

void Show_Array(int array[])
{
	int i;
	for (i=0;i<SIZE;i++)
	{
		cout<<array[i]<<"  ";
		
	}
}

 

posted on 2012-08-19 21:30  至虚极,守静笃  阅读(127)  评论(0编辑  收藏  举报

导航