title: Using a list as indexes to print certain elements from another list
body: <p>I have this problem I am currently working on in C++.</p>
  
  <p>You are given a list, L, and another list, P, containing integers sorted in ascending
  order. The operation printLots(L,P) will print the elements in L that are in positions
  specified by P. For instance, if P = 1, 3, 4, 6, the elements in positions 1, 3, 4, and 6
  in L are printed. Write the procedure printLots(L,P). You may use only the public
  STL container operations. </p>
  
  <p>This is the code I have so far.</p>
  
  <pre><code>void printLots(list&lt;int&gt; L, list&lt;int&gt; P)
  {
      list&lt;int&gt;::iterator myListIterator;
  
      for (myListIterator = P.begin();
          myListIterator != P.end();
           ++myListIterator)
      {
          //Not sure what to do here
      }
  }
  </code></pre>
  
  <p>I know I could very easily print the contents of List P, but I'm not sure how to use it as indexes to print elements in those positions in List L. Based on my research, there is no way to directly index a list either so I'm not quite sure where to go from here.</p>