From 566d9f6fb866ad29160b5c08df95a3316483f288 Mon Sep 17 00:00:00 2001 From: Fudgerboy <91767657+Fudgerboy@users.noreply.github.com> Date: Mon, 19 Feb 2024 21:45:24 +0000 Subject: Mon, Feb 19, 2024, 1:45 PM -08:00 --- wk3/pset/runoff/runoff.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'wk3/pset/runoff') 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; } -- cgit v1.2.3