#define _CRT_SECURE_NO_WARNINGS 1 #include <stdio.h> #include <string.h> void bouble_sort(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 tem = 0; tem = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = tem; flag = 0; } } if (flag == 1) { break; } } } int main() { int arr[] = { 10,9,8,1,7,6,5,4,3,2,1 }; int sz = sizeof(arr) / sizeof(arr[0]); bouble_sort(arr, sz); int i = 0; for (i = 0; i < sz; i++) { printf("%d ", arr[i]); }; return 0; }
标签:sz,arr,tem,int,冒泡排序,flag,简单 From: https://www.cnblogs.com/LiQ0112/p/17169108.html