sort by goals
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user