Hello, I am looking to write all possible combinations of strings stored in a data structure. Here is what I've implemented so far, but I'd like to make it more efficient for larger cases.
Thank you for the advice, I was able to create an implementation based on the next_permutation c++ method. Now, my problem is, I want to make the following line: array_2.push_back(array[i] + array[i+1] + array[i+2]); be more efficient so that it still stores the string when the vector size is more than 3 and etc.?
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
usingnamespace std;
int main() {
int i=0;
int j=0;
vector<string> array;
vector<string> array_2;
array.push_back("one");
array.push_back("two");
array.push_back("three");
do {
// how do I make this more efficient for bigger cases?
array_2.push_back(array[i] + array[i+1] + array[i+2]) ;
} while (std::next_permutation(array.begin(), array.end()));
for (j=0; j < array_2.size(); j++) {
cout << array_2[j] << endl;
}
}