首页 > 编程语言 > 详细

c++字符串的排列组合

时间:2015-06-16 16:55:04      阅读:348      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!