排序算法——希尔排序

一、介绍:

       希尔排序是一种可以减少插入排序中数据比较次数的排序算法,加速算法的进行,排序的原则是将数据区分为特定步长的小区块,然后以插入排序算法对小区块内部进行排序,经历过一轮排序则减少步长,直到所有数据都排序完成。

演示:

首先步长step的值是用待查找的数据长度决定的,初始值为step = 待查找数据的长度/2

视频演示:

希尔排序更多实用攻略教学,爆笑沙雕集锦,你所不知道的游戏知识,热门游戏视频7*24小时持续更新,尽在哔哩哔哩bilibili 视频播放量 107、弹幕量 1、点赞数 0、投硬币枚数 0、收藏人数 1、转发人数 0, 视频作者 浅陌95sss, 作者简介 记录自己的学习成果,分享自己的快乐,相关视频:快速排序,冒泡排序演示,选择排序演示,学习记录--循环列表,直接插入排序演示,学习记录--网络状态机实现,学习记录--设计模式之命令模式,排行榜模拟,学习记录--Rpg雷达图,学习记录--BFS寻路算法icon-default.png?t=N7T8https://www.bilibili.com/video/BV1eS4y15761/?spm_id_from=333.999.0.0运行代码:

  void ShellSort(int[] data)
  {
      int step = data.Length / 2;
      int preIdx , current = 0;
      while (step > 0)
      {
          for (int i = step; i < data.Length; i++)
          {
              preIdx = i - step;
              current = data[i];

              while (preIdx >= 0 && data[preIdx] > current)
              {
                  data[preIdx + step] = data[preIdx];
                  preIdx -= step;
              }
              data[preIdx + step] = current;
          }
          step = step / 2;
      }
  }
 void ShellSort2(int[] data)
 {
     int step = data.Length / 2;
     int preIdx, current = 0;
     while (step > 0)
     {
         for (int i = 0; i < data.Length - step; i +=step)
         {
             preIdx = i;
             current = data[i + step];

             while (preIdx >= 0 && data[preIdx] > current)
             {
                 data[preIdx + step] = data[preIdx];
                 preIdx -= step;
             }
             data[preIdx + step] = current;
         }
         step = step / 2;
     }
 }

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值