# Pset3: Tideman - Sort_pairs function

I am trying to solve sort_pairs by including a property - int winsize - into the struct of pair.

The new pair struct is:

``````typedef struct
{
int winner;
int loser;
int winsize;
}
pair;
``````

I include winsize when initializing pairs under add_pairs:

``````void add_pairs(void)
{
// TODO
for (int i = 0; i < candidate_count; i++)
{
for (int j = 0; j < candidate_count; j++)
{
if (i != j && preferences[i][j] > preferences[j][i])
{
pairs[pair_count].winner = i;
pairs[pair_count].loser = j;
pairs[pair_count].winsize = preferences[i][j];
pair_count += 1;
}
}
}
return;
}
``````

When it comes to sort_pairs, all my test cases seem to sort in descending order, but check50 still highlights it as incorrect. I've tried the various edge cases I know, and incorporated answers from similar questions, but to no avail. I've tried both selection and bubble sort. Appreciate if someone could help! Thanks in advance.

``````void sort_pairs(void)
{
// TODO
int counter = -1;
pair temp;
while (counter != 0)
{
counter = 0;
for (int i = 0; i < pair_count-1; i++)
{
if (pairs[i].winsize < pairs[i+1].winsize)
{
temp = pairs[i];
pairs[i] = pairs[i+1];
pairs[i+1] = temp;
counter += 1;
}
}
}
return;
}
``````
• hey, have you solved it? i'm having the same issue here May 19 '20 at 17:40
• In your add_pairs function, shouldn't `winsize` by updated incrementally, such that `pairs[pair_count].winsize++;` instead of `pairs[pair_count].winsize = preferences[i][j]` ? Not sure if this will help. Jun 8 '20 at 8:38

check50 doesn't care about how you implemented `add_pairs` when it's testing `sort_pairs`, so it doesn't initialize the `winsize` property. You'll need to remove that property, and access it in `sort_pairs`. In the problem directions it says