diff options
author | Fudgerboy <91767657+Fudgerboy@users.noreply.github.com> | 2024-02-19 21:45:24 +0000 |
---|---|---|
committer | Fudgerboy <91767657+Fudgerboy@users.noreply.github.com> | 2024-02-19 21:45:24 +0000 |
commit | 566d9f6fb866ad29160b5c08df95a3316483f288 (patch) | |
tree | 9bbb14c923a0e65adb480849ae76dc9a52924c18 /wk3/pset/runoff | |
parent | 8ae2f3a923a4a4b9c02daf665d9953a21191ccb2 (diff) |
Mon, Feb 19, 2024, 1:45 PM -08:00
Diffstat (limited to 'wk3/pset/runoff')
-rw-r--r-- | wk3/pset/runoff/runoff.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/wk3/pset/runoff/runoff.c b/wk3/pset/runoff/runoff.c index 4d74680..c86de87 100644 --- a/wk3/pset/runoff/runoff.c +++ b/wk3/pset/runoff/runoff.c @@ -172,21 +172,29 @@ bool print_winner(void) } } return false; - } // Return the minimum number of votes any remaining candidate has int find_min(void) { - if (candidates[dead[0]].votes > candidates[i].votes) // if the new candidate has more less than previous + int dead[candidate_count]; + dead[0] = 0; + for (int j = 1; j < candidate_count; j++) + { + dead[j] = -1; + } + for (int i = 0; i < candidate_count; i++) { - // clear the list of dead - for (int j = 1; j < candidate_count; j++) + if (candidates[dead[0]].votes > candidates[i].votes) // if the new candidate has more less than previous { - dead[j] = -1; + // clear the list of dead + for (int j = 1; j < candidate_count; j++) + { + dead[j] = -1; + } + // put it at the start of the new list + dead[0] = i; } - // put it at the start of the new list - dead[0] = i; } return 0; } |