title: Some problem about the algorithm of merging two lists
body: <p>I have some problem when I practice writing the algorithm of merging two lists.</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include&lt;iostream&gt;
  #include&lt;vector&gt;
  using namespace std;
  int main(){
      vector&lt;int&gt; list1,list2;
      int tmp;
      cin&gt;&gt;tmp;
      while(tmp!=-1){
          list1.push_back(tmp);
          cin&gt;&gt;tmp;
      }
      cin&gt;&gt;tmp;
      while(tmp!=-1){
          list2.push_back(tmp);
          cin&gt;&gt;tmp;
      }
      vector&lt;int&gt; list3(list1.size()+list2.size());
      vector&lt;int&gt;::iterator iter1=list1.begin();
      vector&lt;int&gt;::iterator iter2=list2.begin();
      while(iter1!=list1.end()&amp;&amp;iter2!=list2.end()){
          if(*iter1&lt;*iter2){
              list3.push_back(*iter1);
              iter1++;
          }
          else{
              list3.push_back(*iter2);
              iter2++;
          }
      }
      while(iter1!=list1.end()){
          list3.push_back(*iter1);
          iter1++;
      }
      while(iter2!=list2.end()){
          list3.push_back(*iter2);
          iter2++;
      }
      if(list3.size()==0) cout&lt;&lt;"NULL";
      for(int i=0;i&lt;list3.size();i++){
          cout&lt;&lt;list3[i];
          if(i!=list3.size()-1){
              cout&lt;&lt;" ";
          }
      }
      return 0;
  }
  </code></pre>
  
  <p><strong>console input:</strong></p>
  
  <p>1 3 5 -1</p>
  
  <p>2 4 6 8 10 -1</p>
  
  <p><strong>expected output result:</strong>
  1 2 3 4 5 6 8 10</p>
  
  <p><strong>actual output result：</strong>
  0 0 0 0 0 0 0 0 1 2 3 4 5 6 8 10</p>