permutation prev

#include <iostream>#include <string>#include <algorithm>using namespace std;//next_permutation()全排列的下一个//prev_permutation()全排列的前一个,括号中都为数组的起始结束位置的指针void print_int(int a[], int length) {//这个用来输出数组for (int i = 0; i < length; i++) {cout << a[i] << " ";}cout << "\t";}int main() {int t_int1[4] = {1, 2, 3, 4}, t_int2[4] = {4, 3, 2, 1};string t_str1 = "abcd", t_str2 = "dcba";cout << "use next_permutation:" << endl << endl;cout << "for int:" << endl << endl;print_int(t_int1, 4);while (next_permutation(t_int1, &t_int1[4])) {//当没有下一个时返回falseprint_int(t_int1, 4);}cout << endl;cout << endl << "for str:" << endl << endl;cout << t_str1 << " \t";while (next_permutation(t_str1.begin(), t_str1.end())) {cout << t_str1 << " \t";}cout << endl << endl;cout << "use prev_permutation:" << endl << endl;cout << "for int:" << endl << endl;print_int(t_int2, 4);while (prev_permutation(t_int2, &t_int2[4])) {//当没有前一个时返回falseprint_int(t_int1, 4);}cout << endl;cout << endl << "for str:" << endl << endl;cout << t_str2 << " \t";while (prev_permutation(t_str2.begin(), t_str2.end())) {cout << t_str2 << " \t";}cout << endl;return 0;}

,人性最可怜的就是:我们总是梦想着天边的一座奇妙的玫瑰园,

permutation prev

相关文章:

你感兴趣的文章:

标签云: