/**
* Sorts the list of players alphabetically by name.
* Adapt insertion sort algorithm.
* You can assume that no two players have the same name.
* Question T1. Adapting insertion sort for this method
* could yield efficiencies relative to some other approaches
* for some important special cases.
* Do you agree and if so why? Write about 6 to 10 lines.
*/
public void alphabeticSort() {
Player temp;
for (int i = 0; i < players.size(); i++) {
for (int j = players.size() - 1; j > i; j--)
if (players.get(i).compareTo(players.get(j)) < 0) {
temp = players.get(i);
players.set(i, players.get(j));
players.set(j, temp);
}
}
}
我一直在努力,努力,但我有一些困難,試圖比較,你不能使用<
和>
與<Player>
ArrayList
類。我們也無法使用任何Collection.sort
導入。排序<Player> ArrayList的名稱的字母順序
一個正確的方向將是巨大的!
排序列表,你想使用集合。使用自定義比較器排序()而不是自己編碼... –
似乎他不允許使用'Collections.sort' – janos
感謝您的幫助janos。現在就開始工作吧! – copernicon1543