fork(64) download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <vector>
  4.  
  5. void print(const std::vector<int>& v)
  6. {
  7. for (int e : v) {
  8. std::cout << " " << e;
  9. }
  10. std::cout << std::endl;
  11. }
  12.  
  13. int main()
  14. {
  15. std::vector<int> v = {1,2,3};
  16. // vector should be sorted at the beginning.
  17.  
  18. do {
  19. print(v);
  20. } while (std::next_permutation(v.begin(), v.end()));
  21. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
 1 2 3
 1 3 2
 2 1 3
 2 3 1
 3 1 2
 3 2 1