码迷,mamicode.com
首页 > 编程语言 > 详细

希尔排序

时间:2015-07-21 23:30:16      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:

/// <summary>
    /// 希尔排序
    /// </summary>
    public class ShellSort
    {
        public static void Sort(int[] array)
        {
            //取增量
            int step = array.Length / 2;

            while (step >= 1)
            {
                //无须序列
                for (int i = step; i < array.Length; i++)
                {
                    var temp = array[i];

                    int j;

                    //有序序列
                    for (j = i - step; j >= 0 && temp < array[j]; j = j - step)
                    {
                        array[j + step] = array[j];
                    }
                    array[j + step] = temp;
                }
                step = step / 2;
            }
        }
    }

希尔排序平均时间复杂度为O(n^3/2),最坏时间复杂度为O(n²)。

希尔排序

标签:

原文地址:http://www.cnblogs.com/laixiancai/p/4665748.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!