C# 插入排序算法
2016-05-30 22:56
477 查看
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { int[] a = { 118, 101, 105, 127, 112 }; InsertSort(a); Console.ReadLine(); } static void InsertSort(int[] array) { int j, t; for (int i = 1; i < array.Length; i++) { t = array[i]; j = i - 1; while (j >= 0 && t < array[j]) { array[j + 1] = array[j]; j--; } array[j + 1] = t; Console.WriteLine("第" + i + "步排序结果"); for (int h = 0; h < array.Length; h++) { Console.Write(" " + array[h].ToString()); } Console.WriteLine(); } } } }
![](https://images2015.cnblogs.com/blog/600298/201605/600298-20160530225619352-879865851.png)
相关文章推荐
- C#用链式方法
- C#中Math类的计算整数的三种方法
- C#通用类型转换方法
- C#用DataTable实现Group by数据统计
- c# MD5的加密和解密
- (C#基础) byte[] 之初始化, 赋值,转换。
- c#获取当前应用程序所在路径
- C# 字符串加密解密方法
- c# EF基础记录
- .NET C# Tostring() format 格式化字符串大全
- C# 控制台输出
- C#基础之内存分配
- C# 窗体应用程序制作虚拟键盘按键功能
- C#截取字符串(String.Substring方法)
- C#委托与代理
- C#遍历Dictionary
- 基础知识系列☞C#中→属性和字段的区别
- C#文件创建与使用 冲突问题
- C#学习笔记之ListView控件
- C# 线程间不能调用剪切板的问题 续集