scoreboard with efficient time ?

i want to maintain a scoreboard which contains n players sorted according to their scores, what i have done is :
when player i gets x points (if he is not already the top player) i compare his score with the score of the player above him to swap them if necessary, then i repeat this until i find that the player above him has score greater than his score or until he reaches the top of the list.
the problem with this that it has worst case time of O (n), can it be done in something like O (log n) ??
Last edited on
What do you mean?
Can you post what you have tried? Does the assignment require you to implement the algorithm of O(log n)?
closed account (LA48b7Xj)
Maybe use a std::map.
Topic archived. No new replies allowed.