Why is this code note working (the code compiles and run fine, but is not actually showing the permutations):
int main(int argc, char *argv[])
{
long number;
vector<long> interval;
vector<long>::const_iterator it;
cout << "Enter number: ";
cin >> number;
while(number-->0){
interval.push_back(number);
}
do{
for(it = interval.begin(); it < interval.end(); ++it){
cout << *it << " ";
}
cout << endl;
} while(next_permutation(interval.begin(), interval.end()));
return (0);
}
But after changing this line:
while(next_permutation(interval.begin(), interval.end()));
with:
while(prev_permutation(interval.begin(), interval.end()));
Isn't permutation changing the elements in the vector by acting on positions ?
PS: I've edited the code now.