Feb 14, 2016 at 12:37am UTC
Hi all I am trying to convert this loop that work exactly as I need on chars of strings.
1 2 3 4 5 6 7 8 9 10
void Permutenr(const string& input, string output, int r)
{
if (output.length() == r) {
cout << output << endl;
} else {
for (int i=0; i<input.length(); ++i){
Permutenr(input, output + input[i], r);
}
}
}
to use vectors.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
void Permutenr( vector<string> &input, vector<string> output, int r)
{
if (output.size () == r) {
for (auto &item : output){
cout << item << " " ;
}cout << endl;
} else {
for (int i=0; i<input.size (); ++i)
output.push_back (input[i]);
Permutenr(input,output, r);
}
}
and I am not getting the expected output.
using
vector<string> v{"1" ,"2" }
I am getting
1 1
not (order of output not written explicitly)
1 1
1 2
2 1
2 2
Last edited on Feb 14, 2016 at 12:38am UTC
Feb 15, 2016 at 7:45am UTC
@JLBorges Thanks again for your help with the last two questions I had.
I finished up the program tonight and it all works as intended. Pretty spectacular!