C#算法设计排序篇之03-直接插入排序(附带动画演示程序)
直接插入排序(Straight Insertion Sort)
该文章的最新版本已迁移至个人博客【比特飞】,单击链接 https://www.byteflying.com/archives/679 访问。
直接插入排序是一种最简单的排序方法,其基本操作是将一条记录插入到已排好的有序表中,从而得到一个新的、记录数量增1的有序表。
示例:
public class Program {
public static void Main(string[] args) {
int[] array = { 43, 69, 11, 72, 28, 21, 56, 80, 48, 94, 32, 8 };
StraightInsertionSort(array);
ShowSord(array);
Console.ReadKey();
}
private static void ShowSord(int[] array) {
foreach (var num in array) {
Console.Write($"{num} ");
}
Console.WriteLine();
}
public static void StraightInsertionSort(int[] array) {
for (int i = 1; i < array.Length; i++) {
int sentinel = array[i];
int j = i - 1;
while (j >= 0 && sentinel < array[j]) {
array[j + 1] = array[j];
j--;
}
array[j + 1] = sentinel;
}
}
}
以上是直接插入排序算法的一种实现,以下是这个案例的输出结果:
该文章的最新版本已迁移至个人博客【比特飞】,单击链接 https://www.byteflying.com/archives/679 访问。
8 11 21 28 32 43 48 56 69 72 80 94
分析:
直接插入排序算法的时间复杂度为: 。
AlgorithmMan:
AlgorithmMan by Iori,AlgorithmMan是使用C#开发的一套用于算法演示的工具。
下载链接:AlgorithmMan-StraightInsertionSort
C#算法设计排序篇之03-直接插入排序(附带动画演示程序)的更多相关文章
- C#算法设计排序篇之04-选择排序(附带动画演示程序)
选择排序(Selection Sort) 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/681 访问. 选择排序是一种简 ...
- C#算法设计排序篇之06-堆排序(附带动画演示程序)
堆排序(Heap Sort) 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/685 访问. 堆排序是指利用堆积树(堆)这 ...
- C#算法设计排序篇之09-基数排序(附带动画演示程序)
基数排序(Radix Sort) 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/691 访问. 基数排序属于" ...
- C#算法设计排序篇之08-计数排序(附带动画演示程序)
计数排序(Counting Sort) 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/689 访问. 计数排序是一个非基 ...
- C#算法设计排序篇之07-希尔排序(附带动画演示程序)
希尔排序(Shell's Sort) 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/687 访问. 希尔排序是插入排序的 ...
- C#算法设计排序篇之05-归并排序(附带动画演示程序)
归并排序(Merge Sort) 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/683 访问. 归并排序是建立在归并操作 ...
- C#算法设计排序篇之02-快速排序(附带动画演示程序)
快速排序(Quick Sort) 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/677 访问. 快速排序由C. A. R ...
- C#算法设计排序篇之01-冒泡排序(附带动画演示程序)
冒泡排序(Bubble Sort) 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/672 访问. 它重复地访问要排序的元 ...
- C#算法设计排序篇之10-桶排序(附带动画演示程序)
桶排序(Bucket Sort) 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/693 访问. 桶排序的工作原理是将数组 ...
随机推荐
- 没内鬼,来点干货!SQL优化和诊断
SQL优化与诊断 Explain诊断 Explain各参数的含义如下: 列名 说明 id 执行编号,标识select所属的行.如果在语句中没有子查询或关联查询,只有唯一的select,每行都将显示1. ...
- Ethical Hacking - Web Penetration Testing(3)
EXPLOITATION -File Upload VULNS Simple type of vulnerabilities. Allow users to upload executable fil ...
- Active Directory - Creating users via PowerShell
Method1: Create a user by executing the following PowerShell Script. New-ADUser -name 'Michael Jorda ...
- Python Ethical Hacking - Malware Packaging(1)
PACKAGING Convert python program into an executable that: Packages all program files into a single e ...
- ASP.NET CORE之中间件-自定义异常中间件
参考资料:https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/middleware/?view=aspnetcore-3.1 1.一般A ...
- 性能测试必备知识(4)- 使用 stress 和 sysstat
做性能测试的必备知识系列,可以看下面链接的文章哦 https://www.cnblogs.com/poloyy/category/1806772.html stress 介绍 Linux 系统压力测试 ...
- 字符编码笔记:ASCII,Unicode 和 UTF-8个人理解
一.ASCII 码 我们知道,计算机内部,所有信息最终都是一个二进制值.每一个二进制位(bit)有0和1两种状态,因此八个二进制位(字节(Byte )是计算机信息技术用于计量存储容量的一种计量单位,作 ...
- 京东阅读(web)体验优化
京东有电子书可以购买,可以多端阅读.比如PC客户端,移动端,以及本文提到的PC网站端. 先换个镜头,读书要记笔记(电子版本), 方便以后查阅. 镜头换回来,但是,我们为了方便肯定是想复制,下载啊,分享 ...
- @Autowired还可以注入List和Map
@LoadBalanced@Autowired(required = false)private List<RestTemplate> restTemplates = Collection ...
- 利用74HC595实现的流水灯 Arduino
int big = 2; int push = 3; int datain = 4; void setup() { Serial.begin(9600); pinMode(big, OUTPUT); ...