Cs50 Tideman Solution
This function identifies all pairs of candidates where one is preferred over the other.
void sort_pairs(void) for (int i = 0; i < pair_count - 1; i++) for (int j = 0; j < pair_count - i - 1; j++) int margin1 = preferences[pairs[j].winner][pairs[j].loser] - preferences[pairs[j].loser][pairs[j].winner]; int margin2 = preferences[pairs[j+1].winner][pairs[j+1].loser] - preferences[pairs[j+1].loser][pairs[j+1].winner]; if (margin1 < margin2) pair_t temp = pairs[j]; pairs[j] = pairs[j+1]; pairs[j+1] = temp; Use code with caution. 5. lock_pairs Function (The Trickiest Part) Cs50 Tideman Solution
for (int i = 0; i < candidate_count; i++) This function identifies all pairs of candidates where