C#插入排序
2008-09-04 23:17
260 查看
using System;
namespace InsertionSort
{
/// <summary>
/// 插入排序
/// </summary>
public class InsertionSort
{
public void Sort(int[] list)
{
for (int i = 1; i < list.Length; i++)
{
int temp = list[i];
int j = i;
while ((j > 0) && (list[j - 1] > temp))
{
list[j] = list[j - 1];
j--;
}
list[j] = temp;
}
}
static void Main(string[] args)
{
int[] test = new int[] { 1, 6, 3, 8, 11, 43, 0, 3, 57 };
InsertionSort its = new InsertionSort();
its.Sort(test);
for (int i = 0; i < test.Length - 1; i++)
{
Console.WriteLine("{0}", test[i]);
}
Console.ReadKey();
}
}
}
namespace InsertionSort
{
/// <summary>
/// 插入排序
/// </summary>
public class InsertionSort
{
public void Sort(int[] list)
{
for (int i = 1; i < list.Length; i++)
{
int temp = list[i];
int j = i;
while ((j > 0) && (list[j - 1] > temp))
{
list[j] = list[j - 1];
j--;
}
list[j] = temp;
}
}
static void Main(string[] args)
{
int[] test = new int[] { 1, 6, 3, 8, 11, 43, 0, 3, 57 };
InsertionSort its = new InsertionSort();
its.Sort(test);
for (int i = 0; i < test.Length - 1; i++)
{
Console.WriteLine("{0}", test[i]);
}
Console.ReadKey();
}
}
}
相关文章推荐
- C#插入排序算法实现
- 数据结构(C#)--冒泡、插入、快速、堆、归并、希尔、选择各种排序排序过程比较以及各种排序的所用时间的对比
- 插入排序--直接插入排序(C#)
- C#插入排序
- C# 实现排序--冒泡--选择--插入
- 直接插入排序法C#实现
- 插入排序——C#实现
- C#插入排序和折半排序算法
- 数据结构与算法之C#插入排序
- (C#)插入排序 Insertion Sort
- C# 常用排序方法 冒泡排序,直接选择排序,直接插入排序
- C#、 C++直接插入排序控制台
- C#算法 -- (二)插入排序
- C# 直接插入排序
- 插入排序算法--直接插入算法,折半排序算法,希尔排序算法(C#实现)
- C++、C#、java算法学习日记04----二分插入排序
- C# 数据结构与算法系列(六) 排序之直接插入排序法
- c# 自定义排序类(冒泡、选择、插入、希尔、快速、归并、堆排序等)
- C#插入排序详解
- C#算法----(二)插入排序 (转载)