- usingSystem;
- namespaceShellSorter
- {
- publicclassShellSorter
- {
- publicvoidSort(int[]list)
- {
- intinc;
- for(inc=1;inc<=list.Length/9;inc=3*inc+1);
- for(;inc>0;inc/=3)
- {
- for(inti=inc+1;i<=list.Length;i+=inc)
- {
- intt=list[i-1];
- intj=i;
- while((j>inc)&&(list[j-inc-1]>t))
- {
- list[j-1]=list[j-inc-1];
- j-=inc;
- }
- list[j-1]=t;
- }
- }
- }
- }
- publicclassMainClass
- {
- publicstaticvoidMain()
- {
- int[]iArrary=newint[]{1,5,13,6,10,55,99,2,87,12,34,75,33,47};
- ShellSortersh=newShellSorter();
- sh.Sort(iArrary);
- for(intm=0;m<iArrary.Length;m++)
- {
- Console.Write("{0}",iArrary[m]);
- Console.WriteLine();
- }
- }
- }
- }
C#排序算法 之 希尔排序
最新推荐文章于 2025-02-12 16:28:29 发布