Can anyone help check what is wrong with my logic? I tried implementing lock_pairs using these lines of codes:
void lock_pairs(void)
{
// TODO
int count = 0;
for (int i = 0; i < pair_count; i++)
{
for (int j = i; j < pair_count; j++)
{
if(pairs[i].winner == pairs[j].loser)
{
count++;
}
}
if (count == 0)
{
locked[pairs[i].winner][pairs[i].loser] = true;
}
else
{
locked[pairs[i].winner][pairs[i].loser] = false;
}
}
return;
}
My logic is that the program will check whether a winner in any pairs has been a loser or not. If he/she has, then it will increment count by 1, noticing a cycle. If count has been changed, then pairs would not be locked to avoid the cycle. Else if count == 0, then the pairs are suitable to be locked.
This is what check50 returned:
:) lock_pairs locks all pairs when no cycles
:( lock_pairs skips final pair if it creates cycle
lock_pairs did not correctly lock all non-cyclical pairs
:( lock_pairs skips middle pair if it creates a cycle
lock_pairs did not correctly lock all non-cyclical pairs
Any help is appreciated.