gpt4 book ai didi

c++ - std::next_permutation() 来自 vector 的一部分

转载 作者:行者123 更新时间:2023-11-30 04:36:03 27 4
gpt4 key购买 nike

我正在尝试从 vector 的一部分生成排列。见下文。

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() 需要 BidirectionalIterator 作为参数。

最佳答案

while (next_permutation(myArray.begin()+1, myArray.begin()+3)); 应该有效

关于c++ - std::next_permutation() 来自 vector 的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4804427/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com