Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 对2D数组使用std::next_置换_C++_Algorithm_Permutation - Fatal编程技术网

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));