Search code examples
javasortingreversebubble-sort

Why when I reverse the comparison sign in my bubble sort algorithm does the resulting sorting list not reverse?


Java Code:

    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;
    }

If I change j < ... to j > ... the resulting list is not the previous list inverted, though I would assume it should be. All it's doing is reading numbers.


Solution

  • rolls sleeves up

    You're inverting the sign on the wrong line.