- ·上一篇内容:用C#实现插入排序
- ·下一篇内容:Windows系统反病毒安全保护五要决
用C#实现希尔排序
导读:本文介绍了使用C#实现希尔排序的方法
using System;
namespace ShellSorter
{
public class ShellSorter
{
public void Sort(int [] list)
{
int inc;
for(inc=1; inc <= list.Length/9; inc=3 * inc + 1);
for(; inc>0; inc /= 3)
{
for(int i = inc + 1; i <= list.Length; i += inc)
{
int t = list[i-1];
int j = i;
while((j > inc) && (list[j - inc - 1] > t))
{
list[j - 1] = list[j - inc - 1];
j -= inc;
}
list[j - 1] = t;
}
}
}
}
public class MainClass
{
public static void Main()
{
int[] iArrary = new int[]{1,5,13,6,10,55,99,2,87,12,34,75,33,47};
ShellSorter sh=new ShellSorter();
sh.Sort(iArrary);
for(int m = 0;m < iArrary.Length; m ++)
Console.Write("{0} ",iArrary[m]);
Console.WriteLine();
}
}
}
微信搜索“优雅的代码”关注本站的公众号,或直接使用微信扫描下面二维码关注本站公众号,以获取最新内容。
个人成长离不开各位的关注,你的关注就是我继续前行的动力。