码迷,mamicode.com
首页 > 编程语言 > 详细

c++字符串的排列组合

时间:2015-06-16 16:57:20      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:字符串的排列组合

#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);
}

c++字符串的排列组合

标签:字符串的排列组合

原文地址:http://blog.csdn.net/liuhuiyan_2014/article/details/46518493

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!