计算全排列 Veröffentlicht am 2017-03-01 | 12345678910111213141516171819202122232425262728293031323334353637383940#include<bits/stdc++.h>using namespace std;bool next_permutation(int a[], int s, int e){ if (s == e) return false; int i = e; int j = i; i--; while (true) { if (j == s) return false; if (a[i] >= a[j]) { j = i; i--; } else { int k = e; while (a[k] < a[i])k--; swap(a[i], a[k]); reverse(a+i+1, a+e+1); return true; } }}int main(){ int a[] = {1, 2, 3, 4}; do { for (int i = 0;i < 4;i++) cout << a[i] << " "; printf("\n"); }while(next_permutation(a, 0, 3)); return 0;}