I want to write string generator in C++ which allow me to resume generation of the strings from one string that I give to the function on the input. For example when I give string length=20 to the function, I'll wait some time and I'll stop my program I don't want to start over with string "aaaaaaaaaaaaaaaaaaaa", but I would rather to start next execution with some previously generated string (logged somewhere when program stops).
Here is my code how I do it right now:
void printAllKLengthRec(char set[], string prefix, int n, int k)
{
if (k == 0)
{
cout << (prefix) << endl;
return;
}
for (int i = 0; i < n; i++)
{
string newPrefix;
newPrefix = prefix + set[i];
printAllKLengthRec(set, newPrefix, n, k - 1);
}
}
void printAllKLength(char set[], int k, int n)
{
printAllKLengthRec(set, "", n, k);
}
int main()
{
cout << "Test\n";
char set2[] = { 'a', 'b', 'c', 'd', '.', '\\', '_', 'f' };
int k = 20;
printAllKLength(set2, k, 8);
}
Also, in this revcursive function strings are generated "from the end" (for example last "a" is changed, then second last "a" etc.), do you have any suggestions how to change it to generate strings "from the beginning"?