递归算法---全排列

来源:互联网 发布:mac怎么用u盘重装系统 编辑:程序博客网 时间:2024/05/01 16:31
#include<iostream>using namespace std;template<class type>void perm(type list[],int k,int m){    if(k==m)    {        for(int i=0;i<=m;i++)        {            cout<<list[i]<<' ';        }        cout<<endl;    }    else    {        for(int i=k;i<=m;i++)        {            type temp=list[i];            list[i]=list[k];            list[k]=temp;            perm(list,k+1,m);             type tem=list[i];            list[i]=list[k];            list[k]=tem;        }    }}int main(){    char a[10]="abcde";    perm(a,0,4);}
0 0
原创粉丝点击