Reputation: 16126
i'm trying to generate permutations from a part of a vector. See below.
vector<int> myArray;
myArray.resize(5);
myArray[0] = 1;
myArray[1] = 2;
myArray[2] = 3;
myArray[3] = 4;
myArray[4] = 5;
int i = 0;
do {
for (i = 0; i < myArray.size(); i++) {
printf("%i ", myArray[i]);
}
printf("\n");
} while (next_permutation(myArray.at(1), myArray.at(3)));
I need to generate permutations only between positions 1 and 3. Unfortunately vector::at()
is returning reference, but next_permutation()
needs BidirectionalIterator
as a parameter.
Upvotes: 1
Views: 1244
Reputation: 92864
while (next_permutation(myArray.begin()+1, myArray.begin()+3));
should work
Upvotes: 2