Skip to content

元素下沉 ,如果当前元素小于子元素中最小的,应该直接break吧 #9

Open

Description

@xStone9527
# 删除堆顶元素后, 交换堆尾和空堆顶的位置并实现元素的下沉
def percDown(self, i):
    while (i*2) <= self.currentSize:
        mc = self.minChild(i)
        if self.heapList[i] > self.heapList[mc]:
            temp = self.heapList[i]
            self.heapList[i] = self.heapList[mc]
            self.heapList[mc] = temp
       else:
              break

Activity

  1. xStone9527 commented on Sep 7, 2018

    @xStone9527
    Author

    还有 交换元素 每次弄个temp出来,怪麻烦的,既然已经 python了,为什么不a,b=b,a 呢?

  2. LinjingBi commented on Dec 20, 2018

    @LinjingBi

    我觉得这个python版的剑指offer可能是根据c++版改写过来的,所以有很多地方python都可以更简便,但是因为只是单纯的改写就没有了python的特点。

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