summaryrefslogtreecommitdiff
path: root/wk3/pset/runoff
diff options
context:
space:
mode:
authorFudgerboy <91767657+Fudgerboy@users.noreply.github.com>2024-02-19 21:57:23 +0000
committerFudgerboy <91767657+Fudgerboy@users.noreply.github.com>2024-02-19 21:57:23 +0000
commit41305528e75880ac1cd0025f53f831104817edb5 (patch)
treef64612f56f477869665178fe8a78db9705ef95da /wk3/pset/runoff
parentf2e05d8531caf422d82c57eb512bd3b105c8fc49 (diff)
Mon, Feb 19, 2024, 1:57 PM -08:00
Diffstat (limited to 'wk3/pset/runoff')
-rw-r--r--wk3/pset/runoff/runoff.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/wk3/pset/runoff/runoff.c b/wk3/pset/runoff/runoff.c
index 9ff4d19..17b4bf2 100644
--- a/wk3/pset/runoff/runoff.c
+++ b/wk3/pset/runoff/runoff.c
@@ -187,7 +187,8 @@ int find_min(void)
// look through all candidates
for (int i = 0; i < candidate_count; i++)
{
- if (!candidates[i].eliminated) {
+ if (!candidates[i].eliminated)
+ {
// if the new candidate has less votes than previous
if (candidates[i].votes < candidates[dead[0]].votes)
{
@@ -207,13 +208,29 @@ int find_min(void)
// Return true if the election is tied between all candidates, false otherwise
bool is_tie(int min)
{
- // TODO
- return false;
+ for (int i = 0; i < candidate_count; i++)
+ {
+ if (!candidates[i].eliminated)
+ {
+ if (candidates[i].votes != min) {
+ return false;
+ }
+ }
+ }
+ return true;
}
// Eliminate the candidate (or candidates) in last place
void eliminate(int min)
{
- // TODO
+ for (int i = 0; i < candidate_count; i++)
+ {
+ if (!candidates[i].eliminated)
+ {
+ if (candidates[i].votes == min) {
+ candidates[i].eliminated = true;
+ }
+ }
+ }
return;
}