//冒泡排序
void bubbling(int arr[],int sz)
{
int i = 0;
int k = 1;
for (i = 0; i < sz-1; i++)
//
{
int a = 0;
for (a = 0; a < sz-1-i; a++)
{
if (arr[a] >= arr[a + 1])//,比较,交换
{
int ret = arr[a];
arr[a] = arr[a + 1];
arr[a + 1] = ret;
k = 0;
}
}
if (k == 1)
break;
}
} int main() { int arr[] = { 10,9,8,7,6,5,4,3,2,1 }; int sz = sizeof(arr) / sizeof(arr[0]); int i = 0; bubbling(arr,sz); for (i = 0; i < 10; i++) { printf("%d ", arr[i]);
}
return 0;
}