Finding all the permutations of a string is by a well known Steinhaus–Johnson–Trotter algorithm. But if the string contains the repeated characters such as
AABB,
the
Use the following recursive algorithm:
PermutList Permute(SymArray fullSymArray){
PermutList resultList=empty;
for( each symbol A in fullSymArray, but repeated ones take only once) {
PermutList lesserPermutList= Permute(fullSymArray without A)
for ( each SymArray item in lesserPermutList){
resultList.add("A"+item);
}
}
return resultList;
}
As you see, it is very easy