int main()
{
int i,j,temp,a[10]={1,3,6,56,9,7,4,2,34,69};
for( i=1; i<10;i++) /* 开始遍历这个 */
{
temp = a[i]; /* 将数组中的一个值赋值给temp*/
for(j=i-1;j>=0;j--) /* 取另一个元素 */
{
if(a[j]>temp) /* 比较一下得出较大的然后再进行后移 */
{
a[j+1]=a[j];
}
else
{
break;
}
}
a[j+1]=temp;
}
for(j=0;j<10;j++)
{
printf("%d ",a[j]);
}
return 0;
}
原文地址:http://blog.csdn.net/u011046042/article/details/42014541