title: Are there any better methods to do permutation of string?
body: <pre><code>void permute(string elems, int mid, int end)
  {
      static int count;
      if (mid == end) {
          cout &lt;&lt; ++count &lt;&lt; " : " &lt;&lt; elems &lt;&lt; endl;
          return ;
      }
      else {
      for (int i = mid; i &lt;= end; i++) {
              swap(elems, mid, i);
              permute(elems, mid + 1, end);
              swap(elems, mid, i);
          }
      }
  }
  </code></pre>
  
  <p>The above function shows the permutations of <code>str</code>(with <code>str[0..mid-1]</code> as a steady prefix, and <code>str[mid..end]</code> as a permutable suffix). So we can use <code>permute(str, 0, str.size() - 1)</code> to show all the permutations of one string.</p>
  
  <p>But the function uses a recursive algorithm; maybe its performance could be improved?</p>
  
  <p>Are there any better methods to permute a string?</p>