将{6,7,4,5,1,2,3}排序成递增数列所需要的最下移动次数是多少次,具体的算法是如何实现的?
这个用冒泡排序执行四次
void bubble_sort(int a[], int n)
{
int i, j, temp;
for (j = 0; j < n - 1; j++)
for (i = 0; i < n - 1 - j; i++)
{
if(a[i] > a[i + 1])
{
temp = a[i];
a[i] = a[i + 1];
a[i + 1] = temp;
}
}
}
int main()
{
int number[SIZE] = {95, 45, 15, 78, 84, 51, 24, 12};
int i;
bubble_sort(number, SIZE);
for (i = 0; i < SIZE; i++)
{
printf("%d", number[i]);
}
printf("\n");
}
http://blog.csdn.net/u013074465/article/details/44346135?locationNum=1