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!)
采用了递归仅仅是为了锻炼算法,效率肯定是很低的。
查看全文
相关阅读:
命令行
作业三C++
作业二
0003---简单的a+b问题
0002---五层小山
0001---Hello world
关于OJ的那些事
CDQ分治学习笔记
C++ IO的一些注意点
Vscode配置C++环境
原文地址:https://www.cnblogs.com/RChen/p/178268.html
最新文章
判断一个Object是否为数组Array的方法
Promise
vue 自定义动态弹框
ajax 的 promise
vue 采坑
caller、callee的用法及区别
垂直居中一个img
软件工程实践2019第四次作业——结对编程的需求分析与原型模型设计
软件工程实践2019第三次作业
软件工程实践2019第二次作业
热门文章
软工实践2019第一次作业
第一次个人编程作业
第一次博客作业
第一次结对编程作业
第7组 团队展示
第一次个人编程作业
本周JavaScript学习小结
第一次博客作业
团队作业——王者光耀:team
团队作业——王者光耀:前奏
Copyright © 2011-2022 走看看