剑指Offer-28-字符串排列
2015-11-22 16:02
417 查看
#include <iostream> using namespace std; void print(char* str, int length); void permutation(char* str, int begin, int length); void permutation(char* str, int length) { if (str == NULL || length <= 0) return; permutation(str, 0, length); } void permutation(char* str, int begin, int length) { if (begin == length - 1) { print(str,length); } char t; for (int i = begin; i < length; i++) { t = str[begin]; str[begin] = str[i]; str[i] = t; permutation(str, begin + 1, length); } } void print(char* str, int length) { for (int i = 0; i < length; i++) { cout << str[i]; } cout << endl; } int main() { char string1[] = ""; char string2[] = "a"; char string3[] = "ab"; char string4[] = "abc"; permutation(string1,0); permutation(string2,1); permutation(string3,2); permutation(string4,3); return 0; }
相关文章推荐
- JStorm之Supervisor简介
- Java字符串 String StringBuffer
- bootStrap table实现分页
- bootstrap 新手入门(三) 按钮组件
- HTML5矢量实现文件上传进度条
- JStorm之Nimbus简介
- jquery动画遮罩
- poj2718-Smallest Difference(枚举全排列)
- 浅谈JavaScript中的伪类 (李睿豪)
- 剑指Offer-27-二叉排序树转双向链表
- javascript冒泡排序
- inline-block默认间距的处理方法
- background-position 用法详细介绍
- JavaScript调试的那些事
- Google Protocol Buffers介绍
- Google Protocol Buffers介绍
- zzoffer调整数组顺序使奇数位于偶数前面
- js 字符串转日期
- NSJSONSerialization
- 《剑指offer》——数字在排序数组中出现的次数