c++数字全排列函数

数字的全排列(next_permutation)

1 #include
2 #include /// next_permutation, sort
3 using namespace std;
4 int main () {
5 int myints[] = {1,2,3,1};
6 sort (myints,myints+4);
7
8 do {
9 cout << myints[0] << ’ ’ << myints[1] << ’ ’ << myints[2] << ’ ‘<< myints[3]<<’\n’;
10 } while ( next_permutation(myints,myints+4) ); ///获取下一个较大字典序排列
11
12 cout << "After loop: " << myints[0] << ’ ’ << myints[1] << ’ ’ << myints[2] << ’ ‘<< myints[3] <<’\n’;
13 return 0;
14 }

上一篇:java – 字母表的每个排列最多29个字符?


下一篇:python – 递归排列打印机的时间复杂度