标签:oid public i++ 比较 port class tostring rgs ati
import java.util.Arrays; public class BubbleSort { public static void main(String[] args) { int[] a = { 21, 22, 4, 87, 5, 3, 45, 81, 34 }; System.out.println(Arrays.toString(a)); bubbleSort(a); System.out.println(Arrays.toString(a)); } public static void bubbleSort(int[] arr) { for (int i = 0; i < arr.length; i++) { // 外层循环,控制趟数 for (int j = 0; j < arr.length - 1 - i; j++) { // 比较次数 if (arr[j] > arr[j + 1]) { int tmp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = tmp; } } } } }
标签:oid public i++ 比较 port class tostring rgs ati
原文地址:http://www.cnblogs.com/Tan-Yin-Yin-19971130/p/7956044.html