- 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();
- }
- }
- }
- }
C#排序算法 之 希尔排序
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
上一篇:防止SQL注入问题
下一篇:C#排序算法 之 插入排序
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
【C】排序算法
文章介绍了几种常用的排序,包括其实现思路与具体代码实现。
排序 算法 代码分析 -
排序算法之计数排序的优化
排序算法之计数排序的优化
数组 计数排序 最小值 -
java排序算法之希尔排序
排序算法之希尔排序其实希尔排序的本质就是插入排序,不过希尔排序更加高效,也可以称为缩小增量排序希尔排序实现代码:package
排序算法 java 数据结构 希尔排序 i++