You want to sort the pairs based on the preferences for this winner/loser combination. The ones with the largest preference should come first.
Pick any sorting algorithm (week 3 has quite a collection of those, week 3's website has four shorts directly related), and implement it, comparing based on this preference instead of a simple a < b
. Pick any algorithm that you understand, or maybe use qsort
from stdlib.h
(likely implements the quick sort algorithm, though it is not required to, time complexity might be O(n²), using that one might not be expected for somebody in week 3 even if more comfortable).
edit: In the position where you would compare two array elements a
and b
, you would instead compare preferences[a.winner][a.loser]
and preferences[b.winner][b.loser]
. To change ascending to descending, one would swap <
and >
.