Skip to content
Snippets Groups Projects
Commit d7d60bff authored by TheHresvelgian's avatar TheHresvelgian
Browse files

fixed sortRanking.cpp

parent 421138f8
Branches
No related tags found
No related merge requests found
#include <vector> // vector
#include <iostream> // cout, cin
#include "player.h"
......@@ -7,31 +8,46 @@ using namespace std;
extern vector<Player*>playerList;
extern vector<Player*> sortedRankings;
void sortRanking() {
void sortRanking()
{
sortedRankings.clear();
float currentHigh;
float currentHigh = 0;
vector<Player *> listUnsorted = playerList;
vector<Player *> leadingPlayers;
vector<int> listIndex;
do {
for (int i = 0; i < listUnsorted.size(); i++) {
if (listUnsorted[i]->score > currentHigh) {
//listUnsorted[i]->calculateScore();
do
{
currentHigh = 0;
for (int i = 0; i < listUnsorted.size(); i++)
{
listUnsorted[i]->calculateScore();
// cout << endl << listUnsorted[i]->score << " : " << listUnsorted[i]->lastName;
if (listUnsorted[i]->score > currentHigh)
{
leadingPlayers.clear();
leadingPlayers.push_back(listUnsorted[i]);
listIndex.push_back(i);
} else if (listUnsorted[i]->score == currentHigh) {
currentHigh = leadingPlayers[0]->score;
}
else if (listUnsorted[i]->score == currentHigh)
{
leadingPlayers.push_back(listUnsorted[i]);
listIndex.push_back(i);
}
}
for (int i = 0; i < leadingPlayers.size(); i++) {
for (int i = 0; i < leadingPlayers.size(); i++)
{
sortedRankings.push_back(leadingPlayers[i]);
}
leadingPlayers.clear();
for (int i = 0; i < listIndex.size(); ++i) {
listUnsorted[listIndex[i]] = listUnsorted[listUnsorted.size() - 1];
cout << listIndex.size();
for (int i = 0; i < listIndex.size(); ++i)
{
listUnsorted[listIndex[i]] = listUnsorted[listUnsorted.size() - 1 - i];
listUnsorted.pop_back();
}
listIndex.clear();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment