zoukankan
html css js c++ java
希尔排序(C#数据结构学习八)
using
System;
using
System.Collections.Generic;
using
System.Text;
namespace
SoloDataStructure
{
class
MyShellSort
{
/**/
///
<summary>
///
希尔排序
///
</summary>
///
<param name="arr">
需要排序的数列
</param>
static
void
ShellSort (
int
[] arr)
{
int
temp;
//
int
n
=
arr.Length;
int
gap
=
n
/
2
;
//
初始步长
while
(gap
!=
0
)
{
for
(
int
i
=
gap; i
<
arr.Length; i
++
)
{
int
j;
temp
=
arr[i];
for
(j
=
i; j
>=
gap; j
=
j
-
gap)
//
同子序列的插入排序
{
if
(temp
<
arr[j
-
gap])
arr[j]
=
arr[j
-
gap];
//
如果后面的小于前面的,交换位置
else
break
;
}
arr[j]
=
temp;
//
插入
}
gap
/=
2
;
//
缩短步长
}
}
static
void
Main(
string
[] args)
{
int
[] arr
=
new
int
[]
{
99
,
198
,
97
,
96
,
905
,
44
,
93
,
2
,
91
}
;
Console.Write(
"
希尔排序前:
"
);
for
(
int
i
=
0
; i
<
arr.Length; i
++
)
Console.Write(arr[i]
+
"
.
"
);
ShellSort(arr);
Console.Write(
"
\n希尔排序后:
"
);
for
(
int
i
=
0
; i
<
arr.Length; i
++
)
Console.Write(arr[i]
+
"
.
"
);
Console.ReadLine();
}
}
}
查看全文
相关阅读:
今日确定开源近两年来的EA程序
升级了NinjaLoveFish Excel量化表格
到家第一件事就是脱衣服
对挑选完成的股票,进行批量建仓
lua 学习之错误处理
lua 学习之编译
Lambda 演算入门
lua学习之深入函数第二篇
lua学习之深入函数第一篇
lua学习之复习汇总篇
原文地址:https://www.cnblogs.com/solo/p/609674.html
最新文章
服务器如何快速实现一键环境部署?
Zkeys:低门槛、易操作的智能云管理系统
推荐一款疫情期间适合在家办公的远程工具,仅需IP和密码轻松实现远程管理
计算机上常用的计算单位
三军未动粮草(数据)先行
【一些想法】关于工匠精神
前端构建工具的演变
关于CORS(跨域资源共享)的几个http请求头小实验
http缓存的方案总结
js中的对象/对象创建模式/[重温JavaScript基础(五)]
热门文章
js中的原型对象/prototype
引用类型 [重温JavaScript基础(四)]
Java面试—消息队列
Ubuntu16.04 网络配置
MongoDB集群配置
获取股票数据的过程记录
Python股票量化 选股操作不好用 完结
万科A顺利出局,布局一心堂
Python股票量化第一步环境搭建
仁和药业顺利出局,布局地产万科A
Copyright © 2011-2022 走看看