来自向量一部分的 std::next_permutation()
我正在尝试从向量的一部分生成排列。见下文。
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)));
我只需要在位置 1 和 3 之间生成排列。不幸的是 vector::at()
返回引用,但 next_permutation()
需要 Bi DirectionIterator
作为参数。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
while (next_permutation(myArray.begin()+1, myArray.begin()+3));
应该可以工作while (next_permutation(myArray.begin()+1, myArray.begin()+3));
should work