About next_permutation

哈哈没错这个又是我们C++党的语言优势之一,用这个函数可以求当前排序的下一个排序,也就是说可以方便的求全排列,用这个函数需要用到algorithm这个头文件。

与这个函数相反的是prev_permutation,即求前一个排序。

用法:

int类型

int a[1000];

.

.

next_permutation(a,a+n);

n为a数组的长度,若存在当前a之后的排列,这个函数就返回true,若是最后的排列,则返回false,每次执行,a就会变成它的后一个序列。

char类型

char c[1000];

.

.

next_permutation(c,c+strlen(c));

大致与int类型的差不多

string类型

string s[1000];

.

.

next_permutation(s.begin,s.end);

同上

 

posted @ 2016-02-04 15:21  Eggsy  阅读(119)  评论(0编辑  收藏  举报