-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
feat: add ruby code block - heap sort #1261
feat: add ruby code block - heap sort #1261
Conversation
Hi @juminhong, please complete the check list. |
### 堆的长度为 n ,从节点 i 开始,从顶至底堆化 ### | ||
def sift_down(nums, n, i) | ||
while true | ||
# 判断节点i, l, r中值最大的节点,记为ma |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be # 判断节点 i, l, r 中值最大的节点,记为 ma
Please ensure the comments are consistent with those in Python.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, I forgot this guide
9801c7a
ma = i | ||
ma = l if l < n and nums[l] > nums[ma] | ||
ma = r if r < n and nums[r] > nums[ma] | ||
# 若节点i最大或索引l, r越界,则无须继续堆化,跳出 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nums.length / 2 - 1).downto(0) do |i| | ||
sift_down(nums, nums.length, i) | ||
end | ||
# 从堆中提取最大元素,循环n-1轮 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Save as above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious why all the spaces in the comments were removed. Did you use a GPT-like tool? |
### 堆的长度为 n ,从节点 i 开始,从顶至底堆化 ### | ||
def sift_down(nums, n, i) | ||
while true | ||
# 判断节点 i, l, r 中值最大的节点,记为 ma |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please reduce the code to 2-space indentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks,
89273fa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @junminhong, just a little more changes, the rest LGTM
Co-authored-by: khoaxuantu <[email protected]>
Co-authored-by: khoaxuantu <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
If this pull request (PR) pertains to Chinese-to-English translation, please confirm that you have read the contribution guidelines and complete the checklist below:
If this pull request (PR) is associated with coding or code transpilation, please attach the relevant console outputs to the PR and complete the following checklist:
result screenshot