C++ 对2D数组使用std::next_置换
我想打印数组C++ 对2D数组使用std::next_置换,c++,algorithm,permutation,C++,Algorithm,Permutation,我想打印数组AAA的所有排列。我无法理解函数std::next\u permutation的第二个参数 #include <algorithm> char AAA[4][4] = {"abc","123","ABC"}; do { printf("%s %s %d\n",AAA[0],AAA[1],AAA[2]); } while( std::next_permutation( AAA, ???? )); #包括 字符AAA[4][4]={“abc”、“123”
AAA
的所有排列。我无法理解函数std::next\u permutation
的第二个参数
#include <algorithm>
char AAA[4][4] = {"abc","123","ABC"};
do
{
printf("%s %s %d\n",AAA[0],AAA[1],AAA[2]);
} while( std::next_permutation( AAA, ???? ));
#包括
字符AAA[4][4]={“abc”、“123”、“abc”};
做
{
printf(“%s%s%d\n”,AAA[0],AAA[1],AAA[2]);
}while(std::next_置换(AAA,??);
应该是&AAA[3]
还是其他什么?应该是
while( std::next_permutation( std::begin(AAA), std::end(AAA)));
或者(更平淡无奇的是,如果您知道AAA
正好有4个元素)
AAA
最好是std::string
的数组或std::vector
,不过如果循环要遍历所有排列,则需要排序
<> p>并且如果C++您的代码“St::CUT/<代码>流输出,而不是使用<代码> Prtff()/代码> .< /P> <代码> char */COD>,您将比较地址,使用<代码> STD::字符串AAA[]/Cord>。BTW,在ASCII中,代码> >‘A’< /> >和<代码> A′< A′/代码>,因此您应该初始化为<代码> {“123”),“ABC”,“ABC”}
对所有排列进行迭代。这不是真的,Jarod42。因为排序顺序是基于比较地址,而不是指向的数据,这实际上会在所有迭代中循环。不过,无可否认,这可能比OP使用数组(或容器)进行良好规划更幸运因为排序顺序是基于字符串中的数据,而不是它们的地址,所以std::string的排序首先需要排序。
while( std::next_permutation( AAA, AAA + 4));