#include <iostream>
#include <vector>
#include <string>
using std::vector;
using std::string;
void wordsPermutations(vector<string> words, vector<string> current) {
if (words.empty()) {
for (int i = 0; i < current.size(); i++)
std::cout << current[i] << (i + 1 < current.size() ? " " : "");
std::cout << std::endl;
return;
}
for (int i = 0; i < words.size(); i++) {
vector<string> remaining = words;
remaining.erase(remaining.begin() + i);
vector<string> next = current;
next.push_back(words[i]);
wordsPermutations(remaining, next); // Recursive Backtracking
}
}
int main() {
vector<string> words = {"word-1", "word-2", "word-3"};
wordsPermutations(words, {});
}
/*
run:
word-1 word-2 word-3
word-1 word-3 word-2
word-2 word-1 word-3
word-2 word-3 word-1
word-3 word-1 word-2
word-3 word-2 word-1
*/