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();
}
}
}
查看全文
相关阅读:
C++类内存分布
职场人理财之指数基金篇
职场之殇---有些事情千万不能做
职场人为什么需要理财
职场发展之跟对老板有多重要
职场中怎么做好一个演讲
多线程如何按指定顺序同步执行
多线程抢票系统浅析
Spring Boot进阶系列三
Spring Boot进阶系列二
原文地址:https://www.cnblogs.com/solo/p/609674.html
最新文章
Mysql之锁(二)
常见Git操作及关键知识点
linux C/C++服务器后台开发面试题总结
linux c++ 服务器端开发面试必看书籍
奋斗!
liunx工具学习之taskset
liunx系统磁盘满的时候如何排查
多线程学习一:创建线程
锁及锁粒度的详细比喻
C基于客户端的通信实例
热门文章
liunx服务器常见监控指标
读书笔记_Effective_C++_条款四十九:了解new_handler的行为
读书笔记_Effective_C++_条款四十八:了解模板元编程
读书笔记_Effective_C++_条款四十七:请使用trait classes来表示类型信息
读书笔记_Effective_C++_条款四十六:需要类型转换时请为模板定义非成员函数
读书笔记_Effective_C++_条款四十五:运用成员函数模板接受所有兼容类型
读书笔记_Effective_C++_条款四十四:将与参数无关的代码抽离template
读书笔记_Effective_C++_条款四十三:学习处理模板化基类的名称
读书笔记_Effective_C++_条款四十二:了解typename的双重意义
读书笔记_Effective_C++_条款四十一:了解隐式接口和编译期多态
Copyright © 2011-2022 走看看