#include<stdio.h>
#include<string.h>
#define _CRT_SECURE_NO_WARNINGS 1
void bubble_sort(int arr[], int sz)
{
int i = 0;
//排序次数
for (i = 0; i < sz - 1; i++)
{
int j = 0;
//每次排序
for (j = 0; j < sz - 1 -i; j++)
{
if (arr[j] > arr[j + 1])
{
int tmp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = tmp;
}
}
}
}
int main()
{
int i = 0;
int sz = 0;
int arr[] = { 9,8,7,11,5,4,3,2,1,0 };
sz = sizeof(arr) / sizeof(arr[0]);
bubble_sort(arr, sz);//此处只传递数组首元素地址
for (i = 0; i < sz;i++)
{
printf("%d ", arr[i]);
}
return 0;
}
标签:tmp,sz,arr,语言,记录,int,冒泡排序,++,sizeof From: https://blog.51cto.com/u_15985053/6096759