字符全排列
来源:互联网 发布:淘宝怎么进入对方社区 编辑:程序博客网 时间:2024/06/05 08:36
#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);}