Skip to content

Commit f3ae205

Browse files
next_permutation.cpp
1 parent e4f2407 commit f3ae205

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

next_permutation.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <algorithm> // sort, next_permutation
4+
5+
using namespace std;
6+
7+
int main()
8+
{
9+
vector<int> myvec = {1,8,4};
10+
11+
sort(myvec.begin(), myvec.end());
12+
13+
do{
14+
for(int& e : myvec){
15+
cout << e << " ";
16+
}
17+
cout << endl;
18+
}while(next_permutation(myvec.begin(), myvec.end()));
19+
20+
return 0;
21+
}
22+
23+
/*
24+
1 4 8
25+
1 8 4
26+
4 1 8
27+
4 8 1
28+
8 1 4
29+
8 4 1
30+
*/

0 commit comments

Comments
 (0)