Bozo排序

Bogo的变种,继续卖萌。。。

Bogo每次都随机打乱数组,而Bozo每次随机选择两个位置,然后交换这两个位置的值。相同的是不断靠概率不断查看有序了没。。。

public static void bozoSort(int[] A){
    Random rand = new Random();
    while(!inOrder(A)){
        int i = rand.nextInt(A.length);
        int j = rand.nextInt(A.length);
        swap(A, i, j);
    }
}
Java
原文地址:https://www.cnblogs.com/7hat/p/3381382.html