现在的位置: 首页 > 综合 > 正文

字符串的全排列

2018年06月07日 ⁄ 综合 ⁄ 共 378字 ⁄ 字号 评论关闭

字符串全排列

#include<iostream>
using namespace std;
#include<assert.h>
void Permutation(char* pStr, char* pBegin)
{
	//assert(pStr && pBegin); 这个可以替换下面的if
	if(pStr == NULL || pBegin == NULL)
	{
		return;
	}
	if(*pBegin == '\0')
		printf("%s\n",pStr);
	else

	{
		for(char* pCh = pBegin; *pCh != '\0'; pCh++)
		{
			swap(*pBegin,*pCh);
			Permutation(pStr, pBegin+1);
			swap(*pBegin,*pCh);
		}
	}
}
int main(void)
{
	char str[] = "abc";
	Permutation(str,str);
	return 0;
}

抱歉!评论已关闭.