0

I know this has been asked before but I've checked every thread and couldn't find a solution. According to check50, my code for sort_pairs() doesn't work, and I can't figure out what could be wrong with it. Here are the instructions. This is my code:

void sort_pairs(void)
{
    int nswaps = -1;
    pair temp;
    do
    {
        nswaps = 0;
        for (int i = 0; i < pair_count - 1; i++)
        {
            if (preferences[pairs[i].winner][pairs[i].loser] > preferences[pairs[i+1].winner][pairs[i+1].loser])
            {
                temp = pairs[i];
                pairs[i] = pairs[i+1];
                pairs[i+1] = temp;

                nswaps++;
            }
        }
    }
    while (nswaps != 0);
}
2

preferences[pairs[i].winner][pairs[i].loser] > preferences[pairs[i+1].winner][pairs[i+1].loser]

This condition swaps the elements in ascending order while check50 checks for the pairs array for descending order.

| improve this answer | |
  • Oh wow, thank you so much! I don't know how I missed that from the instructions. – jReX Apr 28 at 7:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .