标签:style ar sp for java strong on div bs
冒泡排序算法的运作如下:(从后往前)
java:
package javafu; public class BubbleSort { public static void main(String args[]) { int[] b = { 1, 2, 95, 6, 3, 6 }; System.out.println("排序前:"); for (int k = 0; k < b.length; k++) { System.out.print(b[k] + " "); } sort(b); System.out.println(); System.out.println("排序后:"); for (int k = 0; k < b.length; k++) { System.out.print(b[k] + " "); } } public static void sort(int[] a) { int temp = 0; for (int i = a.length - 1; i > 0; --i) { for (int j = 0; j < i; ++j) { if (a[j + 1] < a[j]) { temp = a[j]; a[j] = a[j + 1]; a[j + 1] = temp; } } } } }
标签:style ar sp for java strong on div bs
原文地址:http://my.oschina.net/zhaoxiaobao/blog/354916