I am trying to generate all subsets of the set {1,2,3}
recursivley. When I run the code though, nothing is printed. I add elements into the vector but printing the vector gives me nothing. Am I not printing in the right place or is something else going on?
#include <stdio.h>
#include <vector>
#include <iostream>
using namespace std;
int n=3;
void gen(int k) {
vector<int> v;
if (k == n + 1) {
cout <<"(";
for (auto i = v.begin(); i != v.end(); ++i){
cout << *i ;
}
cout <<")";
}
else {
gen(k + 1);
v.push_back(k);
gen(k + 1);
v.pop_back();
}
}
int main(){
gen(1);
return 0;
}