#include<stdio.h>
void _sum(int arr[], int sz)//冒泡排序
{
int i = 0;
for (i = 0; i < sz-1; i++)//排序的趟数
{
int j = 0;
int flag = 1;
for (j = 0; j < sz-1-i; j++)
{
if (arr[j] > arr[j+1])
{
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
flag = 0;
}
}
if (flag == 1)
{
break;
}
}
}
int main()
{
int arr[10] = {4,6,8,2,7,1,3,5,9,0};
int ret = 0;
int sz = sizeof(arr) / sizeof(arr[0]);
_sum(arr, sz);
for (ret = 0; ret< sz; ret++)
{
printf("%d ", arr[ret]);
}
return 0;
}
标签:sz,arr,int,ret,++,flag,冒泡排序 From: https://blog.51cto.com/u_15829881/5795133