I'm new to C++, coming from a Python background. I wrote the following
code in C++ based on the Python code found here:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/302478
//beginning
#include
#include
using namespace std;
void looper(vector > nseq, vector comb);
vector > master;
int main() {
int n, C;
vector > seq;
vector holder;
cout << "Enter constant: ";
cin >> C;
cout << "Enter n: ";
cin >> n;
for(i=0; i<=n; i++) {
vector tmp;
for(int j=0; j<=C; j++) {
tmp.push_back(j);
}
seq.push_back(tmp);
}
looper(seq, holder);
return 0;
}
void looper(vector > nseq, vector comb) {
if(nseq.size()>0) {
vector tseq = nseq.at(0);
for(int i=0; i > gseq = nseq;
vector tcomb = comb;
gseq.erase(0);
tcomb.push_back(tseq[i]);
looper(gseq, tcomb);
}
} else {
master.push_back(comb);
}
}
// end
The program dies on the line:
tcomb.push_back(tseq[i]);
in the recursive function. Is my C++ translation accurate from the
original Python?
--
http://mail.python.org/mailman/listinfo/python-list