Skip to content

希尔排序 js写法 for 循环i 的增加有优化的空间 #53

Open

Description

@wujiahui1

for(let i = gap; i < len; i +=gap) {

Activity

  1. zcoding commented on Aug 9, 2021

    @zcoding

    写成 i += gap 说明理解不到位
    当 gap 为1时,i += gap 没问题;
    当 gap 大于1时,for (let i = gap; i < len; i += gap) 直到循环结束只处理了1组数据而已,但实际上有 gap 组数据。其它组数据怎么遍历呢?就是把 i += gap 改为 i++。i++ 可以保证 i 之前的数据,在它们各自的分组里面,都已经处理过了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions