title: Lock_pair function for CS50 Pset 3 Tideman - checking for cycles in a graph
body: <p>I am working on a problem called tideman. The goal is to make a voting program that follows the tideman algorithm. Here is an explanation of the problem : <a href="https://cs50.harvard.edu/x/2020/psets/3/tideman/" rel="nofollow noreferrer">https://cs50.harvard.edu/x/2020/psets/3/tideman/</a> Check50 (a provided test from the course CS50 that I am taking) always returns "lock_pairs skips middle pair if it creates a cycle. lock_pairs did not correctly lock all non-cyclical pairs" The purpose of the lock_pairs function is to go over a graph of winners and losers and make sure that a cycle is not being created (the link to the problem explains it better). I do not exactly understand what skipping the middle pair means, and the program works in situations where a cycle is created when I test it. Also, it passes the check "lock_pairs skips final pair if it creates cycle." I implemented lock_pairs by checking if all of the candidates have an edge on it (overlooking the current loser of the pair) and only locking in the pair if not all candidates have edges (therefore not creating a cycle). How do I fix this?</p>
  
  <pre><code>void lock_pairs(void)
  {
      //checks if a candidate has an edge on it, originally sets all to 0
      bool candidatesEdge[candidate_count];
  
      for(int i = 0; i &lt; candidate_count; i ++)
      {
          candidatesEdge[i] = false;
      }
  
      for (int i = 0; i &lt; pair_count; i ++)
      {
          //variable to see if all others have edges
          bool full = true;
          int j = 0;
  
          //checks through all other candidates for an edge
          while (j &lt; candidate_count &amp;&amp; full == true)
          {
              //if a candidate besides the current being checked doesn't have an edge, full is false
              if (j != pairs[i].loser &amp;&amp; candidatesEdge[j] == false)
              {
                  full = false;
              }
  
              j++;
          }
  
          //if not all candidates have edges, gives the loser of the pair an edge
          if (full == false)
          {
              candidatesEdge[pairs[i].loser] = true;
              locked[pairs[i].winner][pairs[i].loser] = true;
          }
      }
  }
  </code></pre>