java排序 冒泡?+插入排序

冒泡.
public
class insortSort { public static void main(String[] args) { int[] arr = {12, 3, 4, 55, 36, 17, 45, 18, 36}; for (int i = 1; i < arr.length; i++) { for (int j = i - 1; j >= 0; j--) { if (arr[i] < arr[j]) { int temp = arr[j]; arr[j] = arr[i]; arr[i] = temp; } } } for (int b : arr ) { System.out.println(b); } } }
package 真插入;

/**
 * Created by zekaialways give up on 2017/7/21.
 */
public class RealInsortSort {
    public static void main(String[] args) {
        int temp,j;
        int[] a = {6, 2, 4, 1, 8, 3, 9, 11};
        for (int i = 1; i < a.length; i++) {
            temp = a[i];
            for (j = i - 1; j >= 0 && a[j] > temp; j--) {
                a[j + 1] = a[j];
            }
            a[j + 1] = temp;
        }
        for (int b : a
                ) {
            System.out.println(b);

        }

    }
}
原文地址:https://www.cnblogs.com/tangzekai/p/7214581.html