-4
我在這種類型中遇到了一些麻煩。它只會按順序正確顯示第一個文件。任何人看到我做錯了什麼?我一直試圖找出幾個小時,只是沒有看到我做錯了什麼。選擇用對象ArrayList排序
public void sort() {
int i; //loop control
int last; //last position in the arraylist
int max; //position where last alphabetical filename is found
max = 0; //largest position so far is first, since i haven't checked
//I thought i should start at the end and work my way down
for(last = fileList.size()-1; last >= 0; last--) {
for(i = 0; i < fileList.size(); i++) {
if(fileList.get(max).getFileName().compareTo(fileList.get(i).getFileName()) > 0)
max = i;
}
//swap pixfile in last position with the last alphabetical
Pixfile tempPix = fileList.get(last);
fileList.set(last, fileList.get(max));
fileList.set(max, tempPix);
//i thought i would repeat until last = 0 and the arraylist is sorted
}//end for
}
調試存在使用。 – 2013-03-21 01:53:38
請張貼一些樣本輸入和輸出。還要更詳細地描述問題。你爲什麼要實現排序而不使用'Collections.sort(fileList);'? – Jess 2013-03-21 01:56:14