//The Arrange Of String abc ----abc,acb,bac,bca,cab,cba
//Delete Repeat Arrange http://blog.youkuaiyun.com/hackbuteer1/article/details/7462447
//Q:here i use the recursion way to solove this question.What should us do in NO-Recursion??
bool IsSwap(char *begin,char *end)
{
char *p;
for (p = begin; p < end; p++)
{
if (*p == *end)
return false;
}
return true;
}
void StringArrange(char *str,char *begin)
{
if (str == NULL || begin == NULL)
return;
if (*begin == '\0')
cout << str << endl;
else
{
for (char *ch = begin; *ch != '\0'; ch++)
{
if (IsSwap(begin, ch))
{
swap(*begin, *ch);
StringArrange(str, begin + 1);
swap(*begin, *ch);
}
}
}
}
字符串的排列(去除重复项)
最新推荐文章于 2021-07-04 15:37:11 发布