next_permutation()函数在algorithm头文件里,参数为一个数组或字符串的头尾指针,返回值为bool型,调用后自动为数组排序。按照字典序从小到大,比如1234的next_permutation(a,a+4)就是1243.而4321的next_permutation()返回值即为false。
相应的,c++中还有一个prev_permutation()函数,跟next倒着。
若想得到一个全排列,只需要先sort在while(next_permutation())即可。
next_permutation()函数在algorithm头文件里,参数为一个数组或字符串的头尾指针,返回值为bool型,调用后自动为数组排序。按照字典序从小到大,比如1234的next_permutation(a,a+4)就是1243.而4321的next_permutation()返回值即为false。
相应的,c++中还有一个prev_permutation()函数,跟next倒着。
若想得到一个全排列,只需要先sort在while(next_permutation())即可。