0

This function is a recursive function, that lock_pairs is using to understand if a pair will create a cycle:

bool create_cycle(int win_idx, int orig_idx)
{
    if (win_idx == orig_idx) // if it's not the first time of the function and we got to the same candidate, it is a cycle
    {
        return true;
    }
    bool check= false;
    int i;
    for (i = 0; i < candidate_count; i++)
    {
        if (locked[win_idx][i])// if this candidate is prefferd over someone else, the recursion will keep on
        {
            check = true;
            break;
        }
    }
    if (!check)
    {
        return false;// current pair doesnt create a cycle
    }
    return create_cycle(i, orig_idx);

}

I tested my code with cs50 and it says i passed the tests of locking pairs with no cycles, and locking pairs skips middle pair if it creates a cycle.

But I don't understand why I didn't pass the test of :( lock_pairs skips final pair if it creates cycle lock_pairs did not correctly lock all non-cyclical pairs

Can someone help??

You must log in to answer this question.

Browse other questions tagged .