关于全排列

来源:互联网 发布:成都 知乎 编辑:程序博客网 时间:2024/06/06 10:07
#include <cstdlib>#include <iostream>#include <algorithm>#include <vector>using namespace std;void TestArray(){char chs[] = { '4', '6', '5', '3'};int count = sizeof(chs) / sizeof(char);next_permutation(chs + 0, chs + count);printf("TestArray:\n");for (int i = 0; i < count; i++) {printf("%c\t", chs[i]);}printf("\n");}void TestVector(){int n;cin >> n;int *in = new int[n];for (int i = 0; i < n; i++)cin >> in[i];vector<int> vChs(in, in + n);while (next_permutation(vChs.begin(), vChs.end())){    printf("TestVector:\n");for (int i = 0; i < vChs.size(); i++)cout << vChs[i] << " ";//vector<char>::iterator itr;//for (itr = vChs.begin(); itr != vChs.end(); itr++) {//printf("%c\t", *itr);//}printf("\n");}}int main(int argc, char *argv[]){//TestArray();//printf("\n");TestVector();system("PAUSE");return EXIT_SUCCESS;}

 

0 0
原创粉丝点击