I'm trying to implement a bubble sort in the find_min function in pset3 runoff. But It looks like it is not returning the correct min. I think it is because candidates[0].votes may not be the lowest eliminated candidate but I'm not sure how to specify further. Does anyone know what I am doing wrong?
int find_min(void)
{
for (int n = 0; n < candidate_count; n++)
{
for (int d = 0; d < candidate_count - 1; d++)
{
if (candidates[d].votes > candidates[d + 1].votes)
{
int x = candidates[d].votes;
candidates[d].votes = candidates[d + 1].votes;
candidates[d + 1].votes = x;
}
}
}
}
int min = candidates[0].votes;
return min;
}