Hello once again stackoverflow folks, this is really hard and it’s been torturing my brain. What I must do is, a multiplayer server-sided scoreboard. Basically 10 clients are connected into my server application, during this event everytime a player kill another player his kills are increased, each player connected to the server have a class pointer
class CUser
{
(...)
public:
unsigned m_uEventKills;
unsigned m_uEventDeaths;
(...)
};
m_uEvenKills is increased everytime someone kills someone and ofc, m_uEventDeaths also increase for the dying player. Imagine player a,b,c,d,e,f each one of them have random kills (a,b,c,d… is a pointer to CUser) so:
a->m_uEventKills is 72
b->m_uEventKills is 13
c->m_uEventKills is 2
d->m_uEventKills is 44
e->m_uEventKills is 21
f->m_uEventKills is 33
and random values for deaths.
I have this:
int nMax[10];
void OrganizeMax()
{
memset( &nMax, 0, sizeof( nMax ));
(...)
Organize max must fill nMax, from 0 to 9 (10 top users) reading from all connected users (all of them own a pointer to CUser) ->m_uEventKills, and set to nMax[0] the one with most kills, to nMax[1] the second with most kills, to nMax[2] the thirt with most kills and so on…
Any briliant ideas of how to do this?
-Edit
I’ll be more simple, i have 10 vars.
int a,b,c,d,e,f,g,h,i,j;
a = 3;
b = 61;
c = 29;
d = 44;
e = 12;
f = 8;
g = 27;
h = 11;
i = 0;
j = 4;
I need to insert these vars into
int nHold[10];
in decreasing order, how do I do that?
Instead of using
a,b…f, I’d use astd::vectorofCUser(BTW, I don’t likeCUseras a class name):If this is the only order you care about with respect to users, I’d define the ordering as part of the
CUserclass:Then when you need the users sorted into the correct order, you can do:
You will, however, probably need to add an ID number (or something like that) to the
CUserclass to keep track of which user is which, regardless of the order in which they happen to be arranged at the moment.Edit:
To just get the values of
ints in a…j intonHoldin ascending order, you probably want to just insert them in their existing order, then sort: