How to implement ranking system [C#]
I am trying to create a function/algorithm/method in C# to implement a ranking system.
I have an array (naTotals[]) that contains the Total Score for each team (where the team number is represented by the arrays index value)
I need to find a way to determine the RANKING of each team given their Total Score and store their RANK NUMBER in another array (naRankings[] - where the team number is represented by the arrays index value)
So, for example - if naTotals[2] = (20, 5, 15) then after running the function/algorithm/method naRankings[2] should = (0, 2, 1) corresponding to the RANK of each team where 0 is the BEST and 2 the WORST rank (since Team0 had a Total of 20 it was Rank0 as the Best)
This is what I have / my attempt so far:
But as you can see this is far from complete/working - the more I look at it the more I realize it won't work, having a REAL HARD TIME coming up with a viable solution...
But of course I run into the obvious problem of how to save the nNext value before overwriting it and so forth...
There has to be a nice/better way to go about getting these results no? If not maybe some recursive funtion able to "order" the array somehow?
Any help, hints, or advice would be greatly appreciated
Thanks,
I am trying to create a function/algorithm/method in C# to implement a ranking system.
I have an array (naTotals[]) that contains the Total Score for each team (where the team number is represented by the arrays index value)
I need to find a way to determine the RANKING of each team given their Total Score and store their RANK NUMBER in another array (naRankings[] - where the team number is represented by the arrays index value)
So, for example - if naTotals[2] = (20, 5, 15) then after running the function/algorithm/method naRankings[2] should = (0, 2, 1) corresponding to the RANK of each team where 0 is the BEST and 2 the WORST rank (since Team0 had a Total of 20 it was Rank0 as the Best)
This is what I have / my attempt so far:
Code:
// Determine Ranking
int[] naRanking = new int[nPlayersCount];
for (int i = 0; i <= nPlayersCount; i++)
naRanking[i] = 0;
int nTotal = 0;
int nNextTotal = 0;
int sMaxRank = nPlayersCount;
int sCurrentRank = 0;
for (int i = 0; i <+ nPlayersCount; i++)
{
nTotal = naTotals[i];
nNextTotal = naTotals[i+1];
if (nTotal >= nNextTotal)
{
// Somehow do something with naRanking
// Rank this one and hold the next for reranking on recompare with next index?
}
}
But of course I run into the obvious problem of how to save the nNext value before overwriting it and so forth...
There has to be a nice/better way to go about getting these results no? If not maybe some recursive funtion able to "order" the array somehow?
Any help, hints, or advice would be greatly appreciated
Thanks,
Last edited: