title: Check if two single linked lists contain the same data
body: <p>We have to check if two given linked lists contain the same data. Order in this case does not matter, meaning that <code>{1,3,2}</code> and <code>{2,1,3}</code>are same. I think that we should introduce a new variable <code>counter=0</code> and perform the following procedure:</p>
  
  <pre><code>while(node1-&gt;next!=NULL)
  {
      int value=node1-&gt;value;
      if(contains(node2,value)){
          counter++;
      }
  
      node1=node1-&gt;next;
  
      if(counter== number of elements in node 1) 
          return true; 
      else return false;
  }
  </code></pre>
  
  <p>Another method is to sort both lists and compare node by node. Which one is optimal? In the first case it takes O(n^2) operations, while in the second case like Nlog(N)+O(N), (if we use merge sort). Am I right in my thinking? Or is there another optimal method?</p>