我的清單沒有正確排序。有人可以幫忙看看這段代碼嗎?我有一個排序數組,但它沒有被排序。我想要這個主要方法來排序它。用java排序我的想法
public class Main{
public static void main (String [] args){
int [] sort = {3, 1, 2, 4};
int temp = 0;
int backIndex = sort.length;
int index = 0;
while(index <= sort.length){
if (sort[index] >= sort[backIndex]){
temp = sort[index];
sort[index] = sort[backIndex];
sort[backIndex] = temp;
}else{
System.out.print(temp + "," + sort[backIndex]);
}
System.out.print(sort[index] + "," + sort[backIndex]);
index++;
backIndex--;
}
}
}
你的代碼應該做什麼? –
你得到的錯誤是什麼? – Jeremy
「幫忙看看這段代碼」是不是很明確的問題描述。請花點時間並描述*具體*您遇到的問題。 – Pshemo