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();
}
}
}
查看全文
相关阅读:
Solution -「USACO 2020.12 P」Spaceship
Solution -「USACO 2020.12 P」Sleeping Cows
Solution -「HDU #6566」The Hanged Man
Solution -「JOISC 2019」「LOJ #3036」指定城市
HTML5 之required修改默认提示
Js 之内容加密
小程序 之生成接口签名
Js 之Api接口验签
View.js 之加载动画
View.js 之跳转动画
原文地址:https://www.cnblogs.com/solo/p/609674.html
最新文章
剪绳子
股票的最大利润
下一个更大的元素
六边形拼图游戏之给提示
三数之和的多种可能
CF765G. Math, math everywhere
#552. 【UNR #4】同构判定鸭
联赛模拟测试9 C. 小奇的仓库(warehouse)
联赛模拟测试9 B. 征途堆积出友情的永恒
联赛模拟测试9 A. 嚎叫响彻在贪婪的厂房
热门文章
Atcoder Grand Contest 032 E
洛谷 P4426
Topcoder 10748
洛谷 P3643
Educational Codeforces Round 89 题解
Solution -「NOIOL-S 2021」「洛谷 P7470」岛屿探险
Solution -「FJWC 2020」人生
Solution -「ZJOI 2019」「洛谷 P5326」开关
Solution -「CF 1491H」Yuezheng Ling and Dynamic Tree
Solution -「CF 1056G」Take Metro
Copyright © 2011-2022 走看看