zoukankan
html css js c++ java
插入排序
基本思想:
每次将一个待排序的数据元素,插入到前面已经排好序的数列中的适当位置,使数列依然有序;直到待排序数据元素全部插入完为止。
实例代码:
public
class
InsertionSorter
{
public
void
Sort(
int
[] list)
{
for
(
int
i
=
1
;i
<
list.Length;i
++
)
{
int
t
=
list[i];
int
j
=
i;
while
((j
>
0
)
&&
(list[j
-
1
]
>
t))
{
list[j]
=
list[j
-
1
];
--
j;
}
list[j]
=
t;
}
}
}
public
class
MainClassTest3
{
public
static
void
Main()
{
int
[] iArrary
=
new
int
[]
{
1
,
13
,
3
,
6
,
10
,
55
,
98
,
2
,
87
,
12
,
34
,
75
,
33
,
47
}
;
InsertionSorter ii
=
new
InsertionSorter();
ii.Sort(iArrary);
for
(
int
m
=
0
; m
<
iArrary.Length; m
++
)
{
Console.WriteLine();
Console.Write(
"
{0}
"
, iArrary[m]);
}
Console.WriteLine();
}
}
运行结果:
查看全文
相关阅读:
关于向量叉积求得法向量方向判断
Winform菜单之ContextMenuStrip
Winform菜单之Menustrip
MDI窗体及涉及到的相关问题
Winform主窗体的设置
Winform登录、控制软件只运行一次、回车登录
MessageBox详解
Winform窗体
Winform创建解决方案
Winform开发入门集中培训系列文章
原文地址:https://www.cnblogs.com/abcdwxc/p/972278.html
最新文章
SVN服务器搭建和使用(三)
SVN服务器搭建和使用(二)
SVN服务器搭建和使用(一)
二十四种设计模式:访问者模式(Visitor Pattern)
二十四种设计模式:迭代器模式(Iterator Pattern)
二十四种设计模式:单例模式(Singleton Pattern)
二十四种设计模式:代理模式(Proxy Pattern)
二十四种设计模式:抽象工厂模式(Abstract Factory Pattern)
二十四种设计模式:策略模式(Strategy Pattern)
二十四种设计模式:备忘录模式(Memento Pattern)
热门文章
jQuery 当页面 ID 不唯一时,寻找元素
省市区正则表达式
不知道让项目经历说几遍自己才能改正,一定不要产生内存泄漏,尽量把代码优化到最好
MFC下无法为空间添加变量解决
Materix3*3
const修饰符用法
虚函数
欧拉角和四元数详解
自己在完第一遍STL和Directx 9.0 游戏开发编程基础书后的体会
定点法向量
Copyright © 2011-2022 走看看