문자열의 전체 배열 귀속

/* description:    << >> author: JasonZhou date: 2016-03-11 */ 


#include <iostream>
using namespace std;

static int count=0;
// 
void CallAllPermutation(char* perm,int from,int to)  
{  
    if (to<1)
    {
        return;
    }

    if (from==to)
    {
        cout<<++count<<":\t";
        for (int i=0;i<=to;i++)
        {
            cout<<perm[i];
        }
        cout<<endl;
    } 
    else
    {
        for (int j=from;j<=to;j++)
        {
            swap(perm[j],perm[from]);
            CallAllPermutation(perm,from+1,to);
            swap(perm[j],perm[from]);
        }
    }
}  

int main(int argc,char * argv[])  
{  
    char s1[]="abcd";
    CallAllPermutation(s1,0,3);  
    return 0;  
}  

좋은 웹페이지 즐겨찾기