递归排序
来源:互联网 发布:t-sql语法基础知识 编辑:程序博客网 时间:2024/04/30 08:20
# include <stdio.h>/** * 时间:2016年6月5日 11:27:44 * 内容:使用递归来实现排列组合 */# define SWAP(x,y,t) ((t)=(x),(x)=(y),(y)=(t)) void Permutations(char*,int,int); void Info(char*,int); int count=0; int main(void) { char a[]="abcde"; int length=5; Info(a,length); Permutations(a,0,length); printf("总共有%d种排列方式\n",count); return 0; } /** * 递归排序 * @param a 未排序的数组 * @param Start 初始角标 * @param End 终止角标 */ void Permutations(char* a,int Start,int End) { char temp; if (Start==End) { printf("%s\n", a); count++; } else { for (int i=Start;i<End;i++) { SWAP(a[i],a[Start],temp); Permutations(a,Start+1,End); SWAP(a[i],a[Start],temp); } }/*// a开头的,后面bc的所有排列 SWAP(a[0],a[0],temp); Permutations(a,1,2); SWAP(a[0],a[0],temp);// b开头的,后面ac所有排列 SWAP(a[0],a[1],temp); Permutations(a,1,2); SWAP(a[0],a[1],temp);// c开头的,后面ab的所有排列 SWAP(a[0],a[2],temp); Permutations(a,1,2); SWAP(a[0],a[2],temp); */ } void Info(char*a,int n) { for (int i=0;i<n;i++) { printf("%c ",a[i]); } printf("\n"); }
0 0
- 递归排序
- 递归排序
- 递归排序
- 递归排序
- 递归排序
- 递归排序
- 选择排序 冒泡排序 递归
- 排序-归并排序(递归版)
- 快速排序递归调用
- 递归法排序
- 分治递归排序
- 选择排序递归做法
- 快速排序,递归算法
- 递归回溯法排序
- 插入排序 递归 ruby
- 快速排序递归算法
- 递归实现快速排序
- 非递归的排序
- leetcode之Integer Break
- 有关Android多屏幕适配的问题
- 《JavaScript学习笔记》:Ajax的应用
- 《CSS权威指南》学习记录——颜色和背景
- Leetcode Evaluate Reverse Polish Notation
- 递归排序
- Ubuntu软件安装
- 《剑指offer》:[25]二叉树中和为某一值的路径
- linux 6.5下 MySQL 5.6 RPM安装
- 选择排序法
- BIOS/UEFI基础——第一条指令
- Leetcode Paint House
- POJ 3974 Palindrome manacher
- 怎么和自己喜欢的妹子聊天(吼吼吼,我怎么这么笨呢,啊啊啊)