title: How recursion works in a code for computing Permutations of a number
body: <p>I have found this code the internet to computer all possible Permutations for a given Vector ..</p>
  
  <pre><code>import java.util.Vector;
  
  class Permute {
      static int count = 0;
  
      public static void permute(Vector unvisited, Vector visited) {
      if ( unvisited.isEmpty() ) {
          System.out.println("Permutation: "+visited);
          count++;
      }
      else { 
          //System.out.println("Trace: "+visited+" "+unvisited);
          int l = unvisited.size();
          for(int i = 0; i&lt;l; i++) {
          String next = String.valueOf(unvisited.remove(i));
          visited.add(next);
          permute(unvisited,visited);
          unvisited.add(i,next);
          visited.remove(next);
          }
      }
      }
  
      public static void main(String[] args) {    
      Vector objects = new Vector();
  
      objects.add(1);
      objects.add(5);
      objects.add(8);
  
      permute(objects, new Vector() );
          System.out.println(count+" Permutationen gefunden");
      }
  }
  </code></pre>
  
  <p>Bu I have a small problem in understanding the code and the flow of the instructions .
  What I misses is when these two lines are called</p>
  
  <pre><code>    unvisited.add(i,next);
      visited.remove(next);
  </code></pre>
  
  <p>As I see there is a recursion <code>permute(..)</code> function before reaching them !</p>