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 top answer (not the question itself) of this question: C++ recursive permutation algorithm for strings -> not skipping duplicates
For example, for the input "ABC", the output will be: ABC ACB BAC BCA CAB CBA
For the input "ACC", it will be: ACC CAC CCA
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".
I need it to look like this for these inputs:
Input: ACC
Output: ACC CCA CAC
Input: AACC
Output:
AACC ACCA ACAC CCAA CACA CAAC
Any idea how I should modify my algorithm to produce the combinations in this order?
n!/( n!*( n! - k!) ). For example if the input are 3 letters and 2 are the same letter the result is( 3 2 )or3! /( 3! * ( 3! - 2! ) ) = 3, that's why you have 3 outputs in that case - Alberto Bonsanto