赞
踩
//打印一个字符串的所有排列。
void printSequence(char* pChara)
{
int i = 0;
static int MAX_LEN = strlen(pChara);
if (pChara[0] == '\0')
{
for (int i = 0; i < MAX_LEN; i ++)
{
printf("%c", pChara[i + 1]);
}
printf("\n", "");
}
char* tempChar = pChara;
while (*tempChar != '\0' )
{
char* pMyString = new char[MAX_LEN + 1];
memcpy(pMyString, pChara, MAX_LEN + 1);
memcpy(pMyString + i, pMyString + i + 1, MAX_LEN - i);
pMyString[MAX_LEN] = *tempChar;
printSequence(pMyString);
tempChar ++;
i ++;
delete[] pMyString;
}
}
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。