c语言中几个数组成的数的全排列用什么函数

如题所述

C语言中没有吧?C++中倒是有一个:

next_permutation(array,array+arrlength)

使用的头文件是#include <algorithm>

示例:

#include <iostream>
#include <algorithm>    /// next_permutation, sort
using namespace std;
int main () {
    int myints[] = {1,2,3,1};
    sort (myints,myints+4);
    
    do {
        cout << myints[0] << ' ' << myints[1] << ' ' << myints[2] << ' '<< myints[3]<<'\n';
    } while ( next_permutation(myints,myints+4) );    ///获取下一个较大字典序排列
    
    cout << "After loop: " << myints[0] << ' ' << myints[1] << ' ' << myints[2] << ' '<< myints[3] <<'\n';
    return 0;
}

温馨提示:内容为网友见解,仅供参考
相似回答