Java 代码:
public static NHLList bubbleSort(NHLList players) {
for (int i = 0; i < players.size(); i++) {
for (int j = 0; j < players.size()-1; j++) {
if (players.get(j).getPoints() < players.get(j+1).getPoints()) {
PlayerRecord tempPlayer = players.get(j);
players.set(players.get(j+1), j);
players.set(tempPlayer, j+1);
}
}
}
return players;
}
如果我更改j < ...
为j > ...
结果列表,则不是先前的列表倒置,尽管我认为它应该是。它所做的只是读取数字。