晚上好我和我的芽試圖弄清楚為什么程序不會對我們輸入的名稱進行氣泡排序,也許有人可以暗示它。 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;}
添加回答
舉報
0/150
提交
取消