字符全排列

#include<stdio.h>
#include<string.h>

void exchange(char *p,char *q)
{
        if(*p!=*q)
        {
                *p=*p^*q;
                *q=*p^*q;
                *p=*p^*q;
        }
}

void permutation(char *pstr,char *pbegin)
{
        char *current;
        if(*pbegin=='\0')
        {
                printf("%s\n",pstr);
        }
        else
        {
                for(current=pbegin;*current!='\0';current++)
                {
                        exchange(pbegin,current);
                        permutation(pstr,pbegin+1);
                        exchange(pbegin,current);
                }
        }
}
void fullname(char *ptr)
{
        if(ptr==NULL)
        {
                return ;
        }
        permutation(ptr,ptr);
}

int main(int argc,char *argv[])
{
        char ptr[]="key";

        fullname(ptr);
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章