Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
xStone9527 opened this issue Sep 7, 2018 · 2 comments

Comments

@xStone9527
Copy link

# 删除堆顶元素后, 交换堆尾和空堆顶的位置并实现元素的下沉
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
@xStone9527
Copy link
Author

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

@LinjingBi
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants