for(int i=1; i<10;i++)
{
temp = a[i];
int j = i;
while((j>0)&&(a[j-1]>temp))//将大于temp的数值向后移
{
a[j] = a[j-1];
j--;
}
a[j] = temp;//找到比temp小的数值 或是 j已经等于1,将temp插入
}
没有数据交换的过程,节省时间
每次将新加入的数据找到合适位置进行插入
for(int i=1; i<10;i++)
{
temp = a[i];
int j = i;
while((j>0)&&(a[j-1]>temp))//将大于temp的数值向后移
{
a[j] = a[j-1];
j--;
}
a[j] = temp;//找到比temp小的数值 或是 j已经等于1,将temp插入
}
没有数据交换的过程,节省时间
每次将新加入的数据找到合适位置进行插入