/ Published in: C++
Really, this is part of a set of classes that is stored in a Git repository and under MIT license.
The function I'll expose is Circunscription::distributeSeats().
The function I'll expose is Circunscription::distributeSeats().
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
void distributeSeats() { for (int i = 0; i < this->seats; i++) { int mostvoted_code = 0; int votes = 0; for (int j = 0; j < this->candidatures_number; j++) { if (distribution[i][j] > votes) { mostvoted_code = j; votes = distribution[i][j]; } } Candidature *mostvoted = NULL; bool hasItBeenFound = false; this->candidatures->point1stCandidature(); while (!this->candidatures->isCandidaturesListEndPointed() && !hasItBeenFound) { this->candidatures->checkPointedCandidature(mostvoted); if (mostvoted->getCode() == mostvoted_code) hasItBeenFound = true; else this->candidatures->moveCandidaturesPointer(); } int current_seats = mostvoted->getObtainedSeats(); mostvoted->setObtainedSeats(current_seats + 1); this->candidatures->point1stCandidature(); if (i + 1 < this->seats) { distribution[i + 1][mostvoted_code] = distribution[0][mostvoted_code] / (2 * mostvoted->getObtainedSeats() + 1); int k = 0; while (k < this->candidatures_number) { if (k != mostvoted_code) distribution[i + 1][k] = distribution[i][k]; k++; } } } }
URL: https://github.com/garciacarmonaam/saintelague