晚上好
我和我的芽试图弄清楚为什么程序不会对我们输入的名称进行气泡排序,也许有人可以暗示它。
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;
}
慕桂英3389331
相关分类