Your technology certification is waiting. Enroll in Cloud Class ®
string source = "ABC";
int length = source.length();
string current = "";
Generate(source, length, 0, 0, current,);
Open in new window
//start is where in the source to start, position is where in current we are modifying
void Generate(const string &source, const int length, int start, int position, string ¤t)
if(start == length + 1)
printf("%s\n", current); //or however you do output, just output current
for(int i = start; i <= length; ++i) //Note: we allow i == length for the \0 to allow A, AB, etc
current[position] = source[i];
Generate(source, length, i+1, position+1, current);
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.