I tried to create the code to generate all possible combination of the given string in the lexicographical order:
The code that I wrote is:
void get(
Following may help:
bool increase(std::vector& bs)
{
for (std::size_t i = 0; i != bs.size(); ++i) {
bs[i] = !bs[i];
if (bs[i] == true) {
return true;
}
}
return false; // overflow
}
template
void PowerSet(const std::vector& v)
{
std::vector bitset(v.size());
do {
for (std::size_t i = 0; i != v.size(); ++i) {
if (bitset[i]) {
std::cout << v[i] << " ";
}
}
std::cout << std::endl;
} while (increase(bitset));
}
Live example