码迷,mamicode.com
首页 > 其他好文 > 详细

递归解决全排列问题

时间:2017-05-06 21:46:26      阅读:102      评论:0      收藏:0      [点我收藏+]

标签:解决   wap   name   end   using   return   cpp   []   div   

#include <bits/stdc++.h>
using namespace std;
void Perm(char list[],int index,int len)
{
    int i=0 ;
    char tmp ;
    if(index==len)
    {
        for(i=0;i<len;i++)
        {
            cout<<list[i]<<"," ;
        }
        cout<<endl ;
    }
    else
    {
        for(i=index;i<len;i++)
        {
            swap(list[index],list[i]);
            Perm(list,index+1,len) ;
            swap(list[index],list[i]);
        }
    }
}
int main()
{
    char tmp[]={‘1‘,‘2‘,‘3‘,‘4‘} ;
    Perm(tmp,0,4) ;
    return 0 ;
}

  

递归解决全排列问题

标签:解决   wap   name   end   using   return   cpp   []   div   

原文地址:http://www.cnblogs.com/masterchd/p/6818014.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!