# Tideman sort_pairs seems correct but check50 tells me it isn't

Here is the code for my pair sorting algorithm.

``````void sort_pairs(void)
{
for (int i = voter_count; i > 0; i += -1)
{
for (int j = 0; j < pair_count; j++)
{
if(preferences[pairs[j].winner][pairs[j].loser] == i)
{
}
}
}

for (int i = 0; i < pair_count; i++)
{
pairs[i] = sorted_pairs[i];
}

return;
}
``````

Every example I have tested this with appears to work. check50 says everything is correct up to this point. An example I tried:

Candidates: A, B, C, D
Voters: 3

First Voter: A > D > B > C
Second Voter: A > D > C > B
Third Voter: B > A > C > D

This returns the preferences array:

``````0 2 3 3
1 0 2 1
0 1 0 1
0 2 2 0
``````

This gives sorted pairs

0,3 i.e. A,D (Wins by 3-0)
0,2 i.e. A,C (Wins by 3-0)
0,1 i.e A,B (Wins by 2-1)
1,2 i.e B,C (Wins by 2-1)
3,1 i.e D,B (Wins by 2-1)
3,2 i.e. D,C (Wins by 2-1)

This is the order they are returned in and it seems right to me. Have I misunderstood how they are supposed to be sorted? Is there any other explanation? Thank you.