数据结构—排列组合

#include

 

using namespace std;

 

void Permutations(char* p,const int k,const int m);

 

int main()

{

    char s[]="abcd";

    Permutations(s,0,3);

    return 0;

}

 

 

void Permutations(char* p,const int k,const int m)

{

    //a开头的,后面跟着bc的所有排列

    

    //b开头的,后面跟着ac的所有排列

    

    //c开头的,后面跟着ab的所有排列

    

    if(k==m)    //判断是否递归到最后一个

    {

        for(int i=0;i<=m;i++)

            cout<<p[i];

        cout<<endl;

    }

    for(int i=k;i<=m;i++)

    {

        swap(p[k],p[i]);

        Permutations(p,k+1,m);

        swap(p[k],p[i]);

    }

   

 

数据结构—排列组合

posted @ 2016-04-14 17:37  硫酸亚铜  阅读(234)  评论(0编辑  收藏  举报