如下是对8,3,5,1,4,2,7,6的冒泡排序的源代码
#include<stdio.h>
int main()
{
int arr[8] = { 8,3,5,1,4,2,7,6};
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8- 1 - i; j++)
{
if (arr[j] > arr[j + 1])
{
int t = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = t;
}
}
}
for (int i = 0; i < 8; i++)
{
printf("%d\n", arr[i]);
}
return 0;
}