zoukankan
html css js c++ java
没事练习一下算法:全排列的递归算法。
using
System;
namespace
TotalSort
{
/**/
///
<summary>
///
全排列的递归算法
///
</summary>
class
Class1
{
/**/
///
<summary>
///
应用程序的主入口点。
///
</summary>
[STAThread]
static
void
Main(
string
[] args)
{
//
char[] s = "abcdefghijklmnopqrstuvwxyz".ToCharArray();
char
[] s
=
"
abcde
"
.ToCharArray();
TotalSort(s,
0
);
Console.WriteLine(
"
\n\n总数:{0}
"
, resultCount);
Console.ReadLine();
}
static
int
resultCount
=
0
;
public
static
void
TotalSort(
char
[] list,
int
start)
{
int
end
=
list.Length
-
1
;
if
(start
==
end)
{
resultCount
++
;
Console.WriteLine(list);
}
else
{
for
(
int
i
=
start; i
<=
end; i
++
)
{
char
[] temp
=
new
char
[list.Length];
list.CopyTo(temp,
0
);
char
tempc
=
temp[start];
temp[start]
=
temp[i];
temp[i]
=
tempc;
TotalSort(temp, start
+
1
);
}
}
}
}
}
本来想测试 a - z 的全排列,但估算了一下数目相当惊人,只好作罢。
(这个数目是 26!)
采用了递归仅仅是为了锻炼算法,效率肯定是很低的。
查看全文
相关阅读:
二叉树之小球下落
ACM规划型。。
经典函数看待问题。。
用putty连接ubuntu
minheight最小高度的实现(兼容IE6、IE7、FF)(解决IE6不兼容minheight)
elementui里面的form表单i验证input内容已经输入不为空了,但效验还是报错不能为空
js中10位数的时间戳必须*1000才能格式化转换
chrome已安装Vue Devtools在控制台却无显示
elementui使用day.js格式化后端接口里的日期时间戳
elementui分页更改后,需要再次调用获取列表数据函数
原文地址:https://www.cnblogs.com/RChen/p/178268.html
最新文章
阅读: Sams Teach Yourself Emacs in 24 hours
我们We EMC中国卓越研发集团故事
Twiki整理
[转]Swing的第一推动力
工作小结:Emacs的Flex开发环境搭建
Twiki讲座讲稿
Emacs讲座视频, Universidade de Vigo
《与孩子一起学编程》
JAVA面向对象编程课程设计——泡泡堂
更换添加的引擎提高测试效率
热门文章
eclipse整理代码格式快捷键
Assert为TestNG中的断言类
@Test(priority=1)//@Test注解内的方法 表示测试方法的顺序 优先级的意思
java(TM)Platform SE binary
打包时TestNg报错 Using platform encoding (UTF8 actually) to copy filtered resources, i.e. build is platform dependent!
tess4j图片识别 和训练语言库提高图片识别率
打包时TestNg报错 SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
appium 命令行版安装方法
通用数据结构
利用指针可以将A==B?problem简化
Copyright © 2011-2022 走看看