I have this homework problem due tomorrow so if anyone can help it would be much appreciated. I have to write a function that receives letters as a parameter and prints out all combos of those letters, except if there is a duplicate letter in the parameter then I am not suppose to print out duplicates.

ex: "abbc" should print out
abbc abcb acbb babc bacb bbac bbca bcab bcba cabb cbab cbba

My function right now prints out all combos (including duplicates), I can't figure out what I need to add to make it only print the correct ones.

Please help. Below is my function and my main program.

void newanagrams2(string prefix, string remain)
{

int len = remain.length();
if (len == 0) {
cout << prefix << endl;
} else {
for (int i=0; i<len; i++) {
char ch = remain[i];
string s1 = remain.substr(0, i);
string s2 = remain.substr(i+1, len-i-1);
newanagrams2(prefix + ch, s1 + s2);
}
}
}

// This routine is the interface given to users. This routine
// has a parameter list that reflects how users should think
// about using this routine -- they should not have to understand
// how the algorithm works.

void newanagrams(string str)
{
newanagrams2("", str);
}

void main()
{
newanagrams("abcb");
}