//a开头,跟bc所有排列
swap(p[0],p[0]);
Pormuation(p,1,2)
swap(p[0],p[0]);
//b开头,跟ac所有排列
swap(p[0],p[1]);
Pormuation(p,1,2);
swap(p[0],p[1]);
//a开头,跟bc所有排列
swap(p[0],p[2]);
Pormuation(p,1,2);
swap(p[0],p[2]);
*/
//分析上面的,改写成for循环
---------------------------------------------------------------------------
#include<iostream>
using namespace std;
int cnt=0;
void Pormuation(char *p,const int k,const int m);
int main(){
char a[]="abc";
Pormuation(a,0,2);
return 0;
}
void Pormuation(char *p,const int k,const int m){
cout<<"计数为"<<++cnt<<endl;
if(k==m){
for(int i=0;i<=m;i++)
{
cout<<p[i];
}
cout<<endl;
}
else{
for(int i=k;i<=m;i++) {
swap(p[k],p[i]);
Pormuation(p,k+1,m);
swap(p[k],p[i]);
}
}
}
我还是晕的。这可咋办。。。。。
网友评论