Can anyone complete the following program?
Thanks.
void RemoveDuplicates (string& input)
{
string nonRepeatedChars (input);
sort(nonRepeatedChars.begin(), nonRepeatedChars.end());
//cout << nonRepeatedChars <<endl;
string::iterator it = unique(nonRepeatedChars.begin(), nonRepeatedChars.end());
//cout << nonRepeatedChars <<endl;
nonRepeatedChars.erase(it, nonRepeatedChars.end());
cout << "nonRepeatedChars = "<< nonRepeatedChars <<endl;
for(string::iterator i = input.begin(); i != input.end(); i++)
{
cout << "*i = " << *i <<endl;
size_t found = nonRepeatedChars.find(*i);
cout << "found = "<< found <<endl;
if (found != string::npos)
{
input.erase(i);
cout << "input = " << input <<endl;
}
else
{
nonRepeatedChars.erase(found, 1);
cout << "nonRepeatedChars = "<< nonRepeatedChars <<endl;
}
}
cout << "Final Input = " << input <<endl;
}
See Question&Answers more detail:os