title: Recursive algorithm to get combinations of string in particular order
body: <p>There are several algorithms out there that print all combinations of a string, but I need one that prints them out in a specific order. Currently I am using a standard permutation algorithm similar to the one in the <strong>top answer</strong> (not the question itself) of this question: <a href="https://stackoverflow.com/questions/8029994/c-recursive-permutation-algorithm-for-strings-not-skipping-duplicates">C++ recursive permutation algorithm for strings -&gt; not skipping duplicates</a></p>
  
  <p>For example, for the input "ABC", the output will be: ABC ACB BAC BCA CAB CBA</p>
  
  <p>For the input "ACC", it will be: ACC CAC CCA</p>
  
  <p>The outputs are all correct, however I need them in a different order. The input will only consist of the characters 'A' and 'C', and I am sorting the string alphabetically before inputting it to the recursive function for convenience so the input string will always have the same characters together (i.e. AACCC). As for the order, I want to treat the collection of 'C's as a single entity which I shift left for each set of permutations of the characters to the right of the first 'C' only. So for input "ACC", the first output is "ACC" which is OK, the next output should be "CCA" because I shifted all the 'C's one step to the left, then the permutations of "CCA" of all the characters to the right of the first 'C' is the final output which is just "ACA".</p>
  
  <p>I need it to look like this for these inputs:</p>
  
  <p>Input: ACC</p>
  
  <p>Output: ACC CCA CAC</p>
  
  <p>Input: AACC</p>
  
  <p>Output:</p>
  
  <p>AACC ACCA ACAC CCAA CACA CAAC</p>
  
  <p>Any idea how I should modify my algorithm to produce the combinations in this order?</p>