title: Compare List/set elements
body: <p>I'm looking to compare two sets and display the missing elements in second set by iterating over the first set.</p>
  
  <p>I've done using lists but it seems like an overhead iterating over the unordered list to find the elements.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;list&gt;
  using std::list;
  
  bool isExist(list &lt;int&gt; &amp;original, int i)
  {
   list &lt;int&gt;::iterator iter;
  
   for (iter = original.begin(); iter != original.end(); iter++)
   {
    if (*iter == i) {
     original.splice(original.end(), original, iter);
     return true; }
   }
   return false;
  }
  
  void FindMissing(list &lt;int&gt; &amp;original, list &lt;int&gt; &amp;missing)
  {
   int count_exist = 0;
  
   list &lt;int&gt;::iterator iter;
  
   for (iter = missing.begin(); iter != missing.end(); iter++)
   {if (isExist(original, *iter))
    count_exist++;}
  
   int count_missing = original.size() - count_exist;
  
   iter = original.begin();
  
   while(count_missing &gt; 0)
   {
    std::cout &lt;&lt; *iter++ &lt;&lt; std::endl;
    count_missing--;
   }
  }
  
  int main()
  {
   list &lt;int&gt; list_data_1;
   list &lt;int&gt; list_data_2;
  
   //Fill the list.
   for (int i = 0; i &lt; 5; i++)
   list_data_1.push_back(i);
  
   //Fill second list with missing elements.
   list_data_2.push_back(3);
   list_data_2.push_back(1);
   list_data_2.push_back(4);
  
   FindMissing(list_data_1, list_data_2);
  }
  </code></pre>
  
  <p>How would you do the same with set?</p>