title: Print out all permutations of an Array
body: <p>I am working on a program, and I have a function that swaps the positions in an Array of length that is input by a user. However, I am trying to figure out how to print out this function call N! times, which would list all the permutations in the function.</p>
  
  <p>My code for the permutation function is:</p>
  
  <pre><code>static void nextPerm(int[] A){
      for( int i = (n-1); i &gt; 0; i-- ){
          if( A[i] &lt; A[i+1] ){
              A[i] = pivot;
              continue;
          }
          if( A[i] &gt;= A[i+1] ){
              reverseArray(A);
              return;
          }
      }
  
      for( int i = n; i &gt; 0; i--){
          if( A[i] &gt; pivot ){
              A[i] = successor;
              continue;
          }
      }
  
      Swap(pivot, successor);
  
      int[] B = new int[pivot+1];
      reverseArray(B);
  
      return;
  }
  </code></pre>
  
  <p>Should I write a loop in function main, that will print this out n! times?</p>