I am creating a somewhat simple game, and I need to keep track of what players have what score. 25 people will be playing this game at one time, these players will be put into an array:
public static int[] allPlayers = new int[25];
Depending on a correct answer, the current player will earn 100 points, let’s say. So, if player 1 were up, the code would be something similar to the following:
allPlayers[0] += 100;
If player 3 were up, the code on a correct answer would be:
allPlayers[2] += 100;
At the end of the game, I want to determine which player has the accumulated the most amount of points. Please note that I cannot simply sort this array because I need the order of the array to remain intact. If the order is not left intact, I will not be able to tell which player had which points to his/her name.
I’m interested to hear what you all have to say and I look forward to your responses.
Thank you very much,
Evan
No need to sort, just iterate through the array, keeping track of the largest value seen so far and the index of that value.
Handling ties is left as an exercise.