Implementation of Permutation, Combinations and PowerSet in C++ [duplicate]
Using STL: Permutation: using std::next_permutation template <typename T> void Permutation(std::vector<T> v) { std::sort(v.begin(), v.end()); do { std::copy(v.begin(), v.end(), std::ostream_iterator<T>(std::cout, ” “)); std::cout << std::endl; } while (std::next_permutation(v.begin(), v.end())); } Combination: template <typename T> void Combination(const std::vector<T>& v, std::size_t count) { assert(count <= v.size()); std::vector<bool> bitset(v.size() – count, 0); bitset.resize(v.size(), 1); do { for (std::size_t i … Read more