Java 需要冒泡排序帮助

Java bubble sort help needed

晚上好,

我和我的兄弟试图弄清楚为什么程序不会对我们输入的名字进行冒泡排序,也许有人可以提示一下。

 public static void sortDatPlane(String Ref[]){


    int n = Ref.length;
    int k = 1;
    int j = n - 2;
    int i;

    while(k < n){
        i = 0;
        while (i <= j) {
            if(notInOrder(Ref, i, i+1)){
                swap(Ref, i, i+1);
            }
            i++;
        }
        k++;
    }

    for (String Ref1 : Ref) {
        System.out.println(Ref1);
    }

}

public static void swap(String Ref[], int i, int j){
        String temp = Ref[i];
        Ref[i] = Ref[j];
        Ref[j] = temp;
}

public static boolean notInOrder(String Ref[],int i, int j){
    return Ref[i].substring(0,1).compareTo(Ref[j].substring(0,1)) == 1;
}

正如 Ken Y-N 在评论中所述,您只比较字符串的第一个字符(substring(0, 1) 这样做)。删除该部分,它可能会起作用。