#include <iostream>
#include <vector>
void swap(int& a, int& b){
char tmp=a;
a=b; b=tmp;
}
void permutation(std::vector<int> data, std::vector<std::vector<int>>& ret, int depth, int n, int r){
if(depth==r){
std::vector<int> tmp_data(r);
copy(data.begin(), data.begin()+r, tmp_data.begin());
ret.push_back(tmp_data);
return;
}
for(int i=depth; i<n; ++i){
swap(data[depth], data[i]);
permutation(data, ret, depth+1, n, r);
swap(data[depth], data[i]);
}
}
int main(void){
std::vector<int> data={1, 2, 3, 4, 5};
std::vector<std::vector<int>> ret;
permutation(data, ret, 0, data.size(), 3);
for(std::vector<int> set: ret){
for(int s: set) std::cout<<s<<" ";
std::cout<<std::endl;
}
}