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

将abc的全排列输出

时间:2014-10-22 20:07:25      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   ar   for   sp   div   

#include "iostream"

using namespace std;

void swap(char a[],int i,int j){
    char temp;
    temp=a[i];
    a[i]=a[j];
    a[j]=temp;
}

void permutation(char a[],int n,int index){
    if(index==n){
        cout<<a<<endl;
        return;
    }
    
    for(int i=index;i<n;i++){
        if(i!=index){
            swap(a,index,i);
        }
        permutation(a,n,index+1);
        if(i!=index){
            swap(a,index,i);
        }
    }

}

void main(){

    char a[]="abc";
    permutation(a,3,0);


}

 

将abc的全排列输出

标签:style   blog   color   io   os   ar   for   sp   div   

原文地址:http://www.cnblogs.com/593213556wuyubao/p/4044093.html

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