I have an std::vector
of the size 10 and each entry is initially -1. This vector represents a leaderboard for my game (high scores), and -1 just means th
From your description, it appears that the score can be never negative. In that case, I'd recommend the scores to be a vector
of unsigned int
. You can define a constant
const unsigned int INFINITY = -1;
and load your vector with INFINITY
initially. INFINITY
is the maximum positive integer that can be stored in a 32 bit unsigned integer (which also corresponds to -1
in 2's complement)
Then you could simply sort using
sort(v.begin(),v.end());
All INFINITY
will be at the end after the sort.