is there a better way to dothis?
vector<int> selectedNumbers;
int n = 10;//0-9
int k = numbers.size();
fill(numbers.begin(), numbers.begin() + k, 1);
do {
for (int i = 0; i < n; i++) {
if (numbers[i]) {
selectedNumbers.push_back(i);
}
}
do_sth(selectedNumbers);
copy(selectedNumbers.begin(), selectedNumbers.end(), ostream_iterator<int>(cout, " "));
cout << endl;
selectedNumbers.clear();
}
while (prev_permutation(numbers.begin(), numbers.end())) {
};
It's a function. You don't appear to have provided a definition for it. The compiler will complain about that as it can't generate code to call a function is knows nothing about.
@kbw if you go to the link i provided, i just did what they did
If you read what's above the code you blindly copied, they mention putting working code in do_sth which appears to be shorthand in some circles for do_something.
@kbw Thanks but i know how to implement permutation, but its combination that I am having a tough time with. my assignment is for us to use Brute Force for ex.
we have 0-9 with a combination of lets say any 5 elements. {0 1 2 3 4} {4 7 8 9 0} etc .combination will go through all possible combinations of 5 elements using 0-9. then for each combination i have to use permutation.
The code you have above is fine for generating the combinations. Just comment out the do_sth line and uncomment (from the original code) the lines that involved the variable combinations. At the end of the do-while loop you will have all of the combinations in the vector generated
... or ...
replace do_sth with the code that generates your permutations from a single combination.