If there is a string, n characters
e.g. input string = "abcde"
How can I show all the their combinations ?
e.g. abcde, abced, abecd.... etc.
newstr = new string[instr.length()*instr.length()];
for (i = 0; i < ???; i++)
for (j = ?? ?????)
thanks!!
If there is a string, n characters
e.g. input string = "abcde"
How can I show all the their combinations ?
e.g. abcde, abced, abecd.... etc.
newstr = new string[instr.length()*instr.length()];
for (i = 0; i < ???; i++)
for (j = ?? ?????)
thanks!!
I hear there is a permutation function in the STL. Alternatively you can write one of your own using a set of nested loops.
Sorry... Would you mind giving me more infomation??
thx!
Bjarne Stroustrup gives this as an example in 'The C++ Programming Language':
Code:#include <iostream> #include <algorithm> using namespace std; int main() { char v[] = "abcd"; cout << v << '\t'; while(next_permutation(v, v+4)) { cout << v << '\t'; } }
- lmov