字符全排列

#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
void Permutation(char *pStr,char *pBegin){
	if(*pBegin=='\0'){
		printf("%s\n",pStr);
	}else{
		char* pCh =pBegin;
		for(;*pCh!='\0';++pCh){
			char  temp =*pCh;*pCh = *pBegin;*pBegin = temp;
			Permutation(pStr,pBegin+1);
			temp=*pCh;*pCh = *pBegin;*pBegin = temp;
		}//for
	}//else
}//Permutation
void Permute(char *pStr){
	if(pStr==NULL)
		return;
	Permutation(pStr,pStr);
}

int _tmain(int argc, _TCHAR* argv[])
{
	//char *s="abc";/////会报错
	char s[]={"abcd"};
	Permute(s);
	system("pause");
	return 0;
}
abcd
abdc
acbd
acdb
adcb
adbc
bacd
badc
bcad
bcda
bdca
bdac
cbad
cbda
cabd
cadb
cdab
cdba
dbca
dbac
dcba
dcab
dacb
dabc
请按任意键继续. . .
 
 

你可能感兴趣的:(算法,全排列)