0
我有一個從用戶讀入ArrayList中的對象數組,當我嘗試對基於String參數的數據進行冒泡排序時,程序遇到運行時錯誤並且代碼不執行。Bubble sort arraylist
Resort temp;
while (finished = true) {
finished = false;
for (int index = 0; index < numResorts - 1; index++) {
String nam1 = resorts.get(index).getName();
String nam2 = resorts.get(index + 1).getName();
if (nam1.compareTo(nam2) > 0) {
temp = resorts.get(index);
resorts.set(index, resorts.get(index + 1));
resorts.set(index + 1, temp);
//resorts.get(index) = resorts.get(index + 1);
//resorts.get(index + 1) = temp;
finished = true;
}
}
}
現在好了,我覺得完全白癡,謝謝。 – user2808723