title: Permutation without recursion?
body: <p>I was trying to use a for loop to replace the recursion that I usually use, but I found it's harder than I thought. Can anyone tell me how to do it? Thanks!</p>
  
  <p>For example, given a vector of 2, 1, 3. There should be six permutations:</p>
  
  <pre><code>1 2 3
  1 3 2
  2 1 3
  2 3 1
  3 1 2
  3 2 1
  </code></pre>
  
  <p>The vector is below...</p>
  
  <pre><code>vector&lt;int&gt; simple;
  simple.push_back(2);
  simple.push_back(1);
  simple.push_back(3);
  </code></pre>
  
  <p>EDIT: changed the order from 1 2 3 to random order 2 1 3 </p>