diff --git a/codes/zhaohaidong/9790680.java b/codes/zhaohaidong/9790680.java new file mode 100644 index 0000000000000000000000000000000000000000..6189538278ab9ee34dfa4e25ce20812269146ef0 --- /dev/null +++ b/codes/zhaohaidong/9790680.java @@ -0,0 +1,40 @@ +package com.activity-school.codes.zhaohaidong; + +/** + * @program: activity-school + * @description: 一个冒泡排序函数 + * @version: 1.0 + * @author: zhaohaidong + * @create: 2022-09-29 16:26 + */ +public class 9790680 { + + public static void main(String[] args) { + int[] a = {21, 2312, 43, 76, 321, 9, 0, 31, 291, 25, 18, 304, 402}; + bubbleSort(a); + for (int i = 0; i < a.length; i++) { + System.out.print(a[i]); + System.out.print(" "); + } + } + + /** + * 冒泡排序函数 + * + * @param a 原始无序数组 + */ + public static void bubbleSort(int[] a) { + int n = a.length; + for (int i = 0; i < n; i++) { + for (int j = 1; j < n - i; j++) { + if (a[j - 1] > a[j]) { + int t = a[j - 1]; + a[j - 1] = a[j]; + a[j] = t; + } + } + } + } + +} +