Looking through plurality.c's distribution code leads me to believe that the blank (void)print_winner(void) function could be solved with a few loops. But would it be better in practice to solve this using merge sort? More specifically is it asking me to make a new array of sorted vote totals with candidates ordered smallest vote to largest vote and I simply print out the largest vote getter(s) from the array?
Without giving away the answer, could an experienced developer tell me what kind of logic they would use on part specifically? ie: Do you want to use recursion? Whats the best practice here and why?
https://cdn.cs50.net/2020/fall/psets/3/plurality/plurality.c
Forgive the link. My account cannot embed images yet, and I am new to this type of forum.
It looks like in this case since you already have an array of candidates, you can just loop through it once to find the candidate with the most votes. No need to create a new array, just do it in place with O(n) time complexity. Assume candidate[0] has the most votes, and update the winner it as you loop through if another candidate has more votes. You can also add a check to see if someone has the SAME amount of votes, in this case you might need another array to hold "current max" candidates. And update this if there is a new max.