title: Merging vectors
body: <p>So far this is my code, what i am trying to do is say i input 1 2 3 for the fist vector and 
  9 8 7 for the second vector, i want it do print our 1 9 2 8 3 7. but i cant figure it out, can someone point me onto the right direction. Thank you in advance.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;algorithm&gt; 
  #include &lt;vector&gt;
  
  using namespace std;
  
  vector&lt;int&gt; append(vector&lt;int&gt; a, vector&lt;int&gt; b)
  {
      int n = a.size();
      int m = b.size();
      vector&lt;int&gt; c(n + m);
      int i;
  
      for (i = 0; i &lt; n; i++)
          c[i] = a[i];
  
      for (i = 0; i &lt; m; i++)
          c[n + i] = b[i];
  
      return c;
  }
  
  vector&lt;int&gt; merge(vector&lt;int&gt; a, vector&lt;int&gt; b) 
  {
      int n = a.size();
      int m = b.size();
      vector&lt;int&gt; c(n + m);
      int i;
  
      for (i = 0; i &lt; n; i++)
          c[i] = a[i];
  
      for (i = 0; i &lt; m; i++)
          c[n + i] = b[i];
  
      return c;
  }
  
  vector&lt;int&gt; merge_sorted(vector&lt;int&gt; a, vector&lt;int&gt; b)
  {
  
      int n = a.size();
      int m = b.size();
      vector&lt;int&gt; c(n + m);
      int i;
  
      for (i = 0; i &lt; n; i++)
          c[i] = a[i];
  
      for (i = 0; i &lt; m; i++)
          c[n + i] = b[i];
  
  return c;
  }
  
  int main()
  {
      cout &lt;&lt; "Please enter a set of numbers, insert -1 when done.\n";
      vector&lt;int&gt;a;
      bool more = true;
      while (more)
      {
          int n;
          cin &gt;&gt; n;
          if (n == -1)
              more = false;
          else
              a.push_back(n);
     }
  
  
      cout &lt;&lt; "Please enter another set of numbers, insert -1 when done.\n";
      vector&lt;int&gt;b;
      more = true;
      while (more)
     {   
          int m;
          cin &gt;&gt; m;
          if (m == -1)
          more = false; 
          else 
          b.push_back(m);
      }
  
     vector&lt;int&gt;d = append(a,b);
      {
  
          int i;
      cout &lt;&lt; "Appended: ";
          for (i= 0; i &lt; d.size(); i++)
  
          cout &lt;&lt; d[i] &lt;&lt; " ";
      cout &lt;&lt; "\n";
  }
  
  vector&lt;int&gt;r = merge(a,b);
  {
    cout &lt;&lt; "Merged: ";
  
    vector&lt;int&gt; all_nodes(a.size() + b.size());
  
    sort(a.begin(), a.end());
        sort(b.begin(), b.end());
  
        merge(a.begin(), a.end(), b.begin(), b.end(), all_nodes.begin());
    cout &lt;&lt; "\n";
  }
  
      vector&lt;int&gt;z = merge_sorted(a,b);
  {
  
      a.insert( a.end(), b.begin(), b.end() );
      sort( a.begin(), a.end() );
  
          cout &lt;&lt; "Sorted: ";
  
      for (vector&lt;int&gt;::iterator it = a.begin(); it != a.end(); ++it)
          cout &lt;&lt; *it &lt;&lt; " ";
      } 
  }
  </code></pre>