2015年(49)
分类: C/C++
2015-08-17 00:26:08
voidinsertion_sort(intarray[],intfirst,intlast)
{
inti,j;
inttemp;
for
(i=first+1;i<last;i++)
{
temp=array[i];
j=i-1;
//与已排序的数逐一比较,大于temp时,该数移后
while
((j>=0)&&(array[j]>temp))
{
array[j+1]=array[j];
j--;
}
//存在大于temp的数
if
(j!=i-1)
{array[j+1]=temp;}
}
}