sorting - C++ Scoreboard hard time -


hello once again stackoverflow folks, hard , it's been torturing brain. must is, multiplayer server-sided scoreboard. 10 clients connected server application, during event everytime player kill player kills increased, each player connected server have class pointer

class cuser { (...)     public:     unsigned m_ueventkills;     unsigned m_ueventdeaths; (...) }; 

m_uevenkills increased everytime kills , ofc, m_ueventdeaths increase dying player. imagine player a,b,c,d,e,f each 1 of them have random kills (a,b,c,d... pointer cuser) so:

a->m_ueventkills 72 b->m_ueventkills 13 c->m_ueventkills 2 d->m_ueventkills 44 e->m_ueventkills 21 f->m_ueventkills 33 

and random values deaths.

i have this:

int nmax[10];  void organizemax() {     memset( &nmax, 0, sizeof( nmax ));     (...) 

organize max must fill nmax, 0 9 (10 top users) reading connected users (all of them own pointer cuser) ->m_ueventkills, , set nmax[0] 1 kills, nmax[1] second kills, nmax[2] thirt kills , on... briliant ideas of how this?

-edit

i'll more simple, have 10 vars.

int a,b,c,d,e,f,g,h,i,j; = 3; b = 61; c = 29; d = 44; e = 12; f = 8; g = 27; h = 11; = 0; j = 4; 

i need insert these vars

int nhold[10]; 

in decreasing order, how do that?

instead of using a, b ...f, i'd use std::vector of cuser (btw, don't cuser class name):

std::vector<cuser> users; 

if only order care respect users, i'd define ordering part of cuser class:

class cuser {       // ...     bool operator<(cuser const &other) const {           return m_ueventkills < other.m_ueventkills;     } }; 

then when need users sorted correct order, can do:

std::sort(users.begin(), users.end()); 

you will, however, need add id number (or that) cuser class keep track of user which, regardless of order in happen arranged @ moment.

edit:

to values of ints in a...j nhold in ascending order, want insert them in existing order, sort:

nhold[0] = a; nhold[1] = b; //... nhold[9] = j;  std::sort(nhold, nhold+9); 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -