Last active
February 11, 2020 23:26
-
-
Save MathLou/60af356942a61e22b7fbe2a8f8f2b1b7 to your computer and use it in GitHub Desktop.
pset 3 pfunction problems
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int find_min(void) | |
{ | |
int a = candidates[0].votes; | |
int b = candidates[1].votes; | |
int c = candidates[2].votes; | |
if (a != 0 && b != 0 && c != 0) | |
{ | |
if (candidates[0].eliminated == false && candidates[1].eliminated == false && candidates[2].eliminated == false) | |
{ | |
if (a < b && a < c) | |
{ | |
return a; | |
} | |
if (b < a && b < c) | |
{ | |
return b; | |
} | |
if (c < b && c < a) | |
{ | |
return c; | |
} | |
if (a == b && b < c) | |
{ | |
return a; | |
} | |
if (a == c && c < b) | |
{ | |
return a; | |
} | |
if (b == c && c < a) | |
{ | |
return b; | |
} | |
if (a == b && b == c) | |
{ | |
return a; | |
} | |
} | |
if (candidates[0].eliminated == true && candidates[1].eliminated == false && candidates[2].eliminated == false) | |
{ | |
if (b < c) | |
{ | |
return b; | |
} | |
if (b > c) | |
{ | |
return c; | |
} | |
} | |
if (candidates[0].eliminated == false && candidates[1].eliminated == true && candidates[2].eliminated == false) | |
{ | |
if (a < c) | |
{ | |
return a; | |
} | |
if (a > c) | |
{ | |
return c; | |
} | |
} | |
if (candidates[0].eliminated == false && candidates[1].eliminated == false && candidates[2].eliminated == true) | |
{ | |
if (a < b) | |
{ | |
return a; | |
} | |
if (a > b) | |
{ | |
return b; | |
} | |
} | |
return 0; | |
} | |
else | |
return 1; | |
} | |
void eliminate(int min) | |
{ | |
for (int i = 0; i < voter_count; i++) | |
{ | |
for (int j = 0; j < 3; j++) | |
{ | |
if (is_tie(min) == false) | |
{ | |
if (candidates[j].votes == min || candidates[j].votes == 0) | |
{ | |
candidates[j].eliminated = true; | |
} | |
} | |
else | |
{ | |
if (candidates[j].votes == min || candidates[j].votes != 0) | |
{ | |
candidates[j].eliminated = false; | |
} | |
} | |
} | |
} | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment