字符串全排列代码实现
2014-08-03 17:06
183 查看
#include <iostream> #include <string> using namespace std; bool IsSwap(char* perm, int from, int to) { for(int i = from; i < to ; ++i) { if(perm[i] == perm[to]) return false; } return true; } void CalcAllPermutation(char* perm, int from, int to) { if (to <= 1) { return; } if (from == to) { for (int i = 0; i <= to; i++) cout << perm[i]; cout << endl; } else { for (int j = from; j <= to; j++) { if(IsSwap(perm, from, j)) { swap(perm[j], perm[from]); CalcAllPermutation(perm, from + 1, to); swap(perm[j], perm[from]); } } } } int main() { char a[4] = "baa"; CalcAllPermutation(a, 0, 2); return 0; }
相关文章推荐
- 枚举数组中所有可能排列的代码实现 [2004年7月8日 1:5
- c#实现16进制和字符串之间转换的代码
- Ajax 返回字符串的过滤实现代码
- c#实现16进制和字符串之间转换的代码
- jquery 可排列的表实现代码
- 实现对中文字符串数组按照音序排列
- 批处理字符串去空格实现代码
- PHP mb_convert_encoding 获取字符串编码类型实现代码
- 10个经典的字符串hash函数的C代码实现
- javascript下搜索子字符串的的实现代码(脚本之家修正版)
- CreateKeyWord asp实现的由给定的字符串生成关键字的代码
- php实现的简单压缩英文字符串的代码
- 用asp实现的截取指定格式字符串的代码
- 数字转化成字符串 (自己用代码实现)
- 一段实现除去字符串中重复的js代码
- vbs:一段比较精简的代码实现取得字符串的"字节"数
- GetBody asp实现截取字符串的代码
- css+js实现select列表横向排列效果代码
- python 中文字符串的处理实现代码
- 枚举数组中所有可能排列的代码实现 [2004年7月8日 1:57 ]