递归系列-------------全排列递归解法
2014-04-05 20:56
239 查看
#include <stdio.h>
void permutation(char s[], int b, int e)
{
if( (0 <= b) && (b <= e) )
{
if( b == e )
{
printf("%s\n", s);
}
else
{
int i = 0;
for(i=b; i<=e; i++)
{
char c = s[b];
s[b] = s[i];
s[i] = c;
permutation(s, b+1, e);
c = s[b];
s[b] = s[i];
s[i] = c;
}
}
}
}
int main()
{
char s[] = "abcd";
permutation(s, 0, 3);
getchar();
return 0;
}
void permutation(char s[], int b, int e)
{
if( (0 <= b) && (b <= e) )
{
if( b == e )
{
printf("%s\n", s);
}
else
{
int i = 0;
for(i=b; i<=e; i++)
{
char c = s[b];
s[b] = s[i];
s[i] = c;
permutation(s, b+1, e);
c = s[b];
s[b] = s[i];
s[i] = c;
}
}
}
}
int main()
{
char s[] = "abcd";
permutation(s, 0, 3);
getchar();
return 0;
}
相关文章推荐
- vbscript include的办法实现代码第1/2页
- PHP脚本中include文件出错解决方法
- Flex include和import ActionScript代码
- set_include_path在win和linux下的区别
- php include加载文件两种方式效率比较
- How to Auto Include a Javascript File
- 浅谈ASP.NET的include的使用方法
- java/jsp中 中文问题详解
- JSP计数器的制作
- php include和require的区别深入解析
- PHP include_path设置技巧分享
- JS 实现完美include载入实现代码
- JS实现完美include加载功能代码
- JSP开发入门(四)--JSP的内部对象
- 实战 J2EE 开发购物网站 二
- php 中include()与require()的对比
- JSP中include指令和include行为的区别
- asp.net服务器端指令include的使用及优势介绍
- JSP编译指令page、include详解
- jsp中include指令静态导入和动态导入的区别详解