1冒泡排序:
改进的两点:
1)用count保存执行遍历的次数,进入循环后先把count置为0,如果某此没有发生交换,则下一次count为0,直接停止排序
2)用last记录最后一次发生交换的位置,下一次排序只遍历到last的位置
//冒泡排序
void BubbleSort(int InputArrawy[], int N)
{
int i,j,k;
int count = N;
int last = N-1;
for(i = 0; i < count; i++)
{
count = 0;
for(j = 0; j < last ; j++)
{
if(InputArrawy[j] > InputArrawy[j+1])
{
int t = InputArrawy[j];
InputArrawy[j] = InputArrawy[j+1];
InputArrawy[j+1] = t;
count = N;
k = j;
}
}
last = k;
}
}