sort by goals

This commit is contained in:
Cool Guy
2026-05-13 20:00:22 +00:00
parent d73e5d29fd
commit 552de95add
2 changed files with 23 additions and 3 deletions

View File

@@ -129,6 +129,21 @@ public class PlayerList {
}
}
/** Sorts the players in the list by total goals using an Insertion Sort algorithm. */
public void sortByGoals() {
int n = pList.size();
for (int i = 0; i < n; i++) {
HockeyPlayer key = pList.get(i);
int j = i - 1;
while (j >= 0 && pList.get(j).getGoals() < key.getGoals()) {
pList.set(j + 1, pList.get(j));
j--;
}
pList.set(j + 1, key);
}
}
/**
* Locates a player and updates their stats with results from a single game.
*