📄 next_perm_example.cpp
字号:
//Examples of using next_permutation
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
//using pointers
void display(char* c_str)
{
cout<<c_str<<endl;
}
int main()
{
char ca[]="1234";
display(ca);
for(int i=0;i<24-1;++i)
{
next_permutation(ca,ca+4);
display(ca);
}
return 0;
}
/*
//using iterators
void display(vector<char>::iterator begin,vector<char>::iterator end)
{
for(vector<char>::iterator it= begin;it!=end;++it)
cout<<*it;
cout<<endl;
}
int main()
{
//char ca[]="1234";
vector<char> ca;
ca.push_back('1');
ca.push_back('2');
ca.push_back('3');
ca.push_back('4');
display(ca.begin(),ca.end());
for(int i=0;i<24-1;++i)
{
next_permutation(ca.begin(),ca.end());
display(ca.begin(),ca.end());
}
return 0;
}
*/
/*
//using arrays of string
void display(string* strstart, string* strend)
{
for(string* it= strstart;it!=strend;++it)
cout<<*it<<" ";
cout<<endl;
}
int main()
{
string* strarray=new string[3];
strarray[0]="Red";
strarray[1]="Green";
strarray[2]="Blue";
display(strarray,strarray+3);
for(int i=0;i<6-1;++i)
{
next_permutation(strarray,strarray+3);
display(strarray,strarray+3);
}
delete [] strarray;
return 0;
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -