Obtaining indices and elements - vector problem
<p>I want to do following thing; I tried, but not succeeded. So I am expecting some way to solve this.</p>

<p>I have two vectors. One is <code>vector&lt;int&gt; myvector</code> and the other one is vector of <code>Plane</code> (where <code>Plane</code> is a created class which stores plane parameters and other properties of planes)</p>

<p>For example I will give you some example for my case; if</p>

<pre><code>myvector = &lt;0, 1, 4, 6, 7, 10, 12, 13, 14, 15, 16, 17&gt;
myvector_new = &lt;plane0, plane1, plane4, plane6, plane7, plane10, plane12, plane13, plane15, plane16, plane17&gt;
</code></pre>

<p>(the sizes of above 2 vectors are same.)</p>

<p>I want to modify these 2 existing vectors or create 2 new vectors as such,</p>

<pre><code>myvector_new = &lt;0,1,-1,-1, 4,-1, 6, 7,-1,-1, 10,-1, 12, 13, 14, 15, 16, 17&gt;
myplane_new = &lt;plane0, plane1, null, null,plane4,null,plane6, plane7,null,null, plane10,…., plane17&gt;
</code></pre>

<p>(i.e. if I say what I need in another way; first, I want a vector whose size is equal to the maximum element of <code>myvector</code>. Then I can directly use the indices of this vector to get the inside element values for my other programs, if it is valid value. But, new vector must contain only the above valid values (i.e already existed values). So, I wish to put a negative value to represent other values that I am going to push back or insert. At the same time, I want to modify my second vector <code>myplane</code>, including only the previously existed valid values of class <code>Plane</code> and also containing invalid values (like null plane or empty objects).</p>

<p>So, I tried this with vector insert function, but I couldn’t. Then I tried to create new vectors as follows;</p>

<pre><code>//some codes above to create myvector and myplane

Vector&lt;int&gt; myvector_new;
Vector&lt;Plane&gt; myplane_new;

 for(int k=0; k&lt;myvector.size(); k++){        
      if (myvector.at(k)==k){
          myvector_new.push_back(k);
          myplane_new.push_back(myplane.at(k))
      }    
      else{
          for(int m=k; m&lt;myvector.at(k); m++){
              myvector_new.push_back(-1);
              myplane_new.push_back(null); 
          }       
          myvector_new.push_back(myvector.at(k));
          myplane_new.push_back(myplane.at(k)); 
          }
      }

When I cheked myvector_new (I checked only this sofar) simply as follows;

  for(int m=0;m&lt;myplane_new.size();m++){
          cout&lt;&lt;myplane_new[m]&lt;&lt;" ";
          }
</code></pre>

<p>I got the following result. Please anyone help me to modify my codes.</p>

<blockquote>
  <p>0 1 -1 -1 4 -1 -1 -1 6 -1 -1 -1 7 -1 -1 -1 -1 -1 10 -1 -1 -1 -1 -1 -1 12 -1 -1 -
  1 -1 -1 -1 13 -1 -1 -1 -1 -1 -1 14 -1 -1 -1 -1 -1 -1 15 -1 -1 -1 -1 -1 -1 16 -1
  -1 -1 -1 -1 -1 17</p>
</blockquote>

<p>But, this is wrong. If anyone can help me to modify my codes to be able to get required result, it is highly appreciating.</p>
