您的位置:首页 > 编程语言 > C语言/C++

c++字符串的排列组合

2015-06-16 15:09 302 查看
#include <iostream>
#include <string.h>
using namespace std;
static int sum = 0;
void Swap(char &a, char &b)
{
char tmp = a;
a = b;
b = tmp;
}
void Grial(char *s1, char *s2)
{
if (s1 == NULL || s2 == NULL)return;
if (*s2 == '\0')
cout << s1 << endl;
for (char *p = s2; *p != '\0'; p++)
{
//sum++;
Swap(*p,*s2);
Grial(s1,s2+1);
//if (*p!=*s2)
Swap(*p,*s2);
}
//  cout << sum << endl;
}
void Grial(char *str)
{
Grial(str, str);
}
int main()
{
char *str = new char[5];
strcpy(str,"12345");
Grial(str);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: