title: How would you calculate all possible permutations of 0 through N iteratively?
body: <p>I need to calculate permutations iteratively.  The method signature looks like:</p>
  
  <p><code>int[][] permute(int n)</code></p>
  
  <p>For <code>n = 3</code> for example, the return value would be:</p>
  
  <pre><code>[[0,1,2],
   [0,2,1],
   [1,0,2],
   [1,2,0],
   [2,0,1],
   [2,1,0]]
  </code></pre>
  
  <p>How would you go about doing this iteratively in the most efficient way possible?  I can do this recursively, but I'm interested in seeing lots of alternate ways to doing it iteratively.</p>