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

feat: add ruby code block - merge sort #1260

Merged
merged 6 commits into from
Apr 30, 2024

Conversation

junminhong
Copy link
Contributor

@junminhong junminhong commented Apr 10, 2024

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:

  • This PR represents the translation of a single, complete document, or contains only bug fixes.
  • The translation accurately conveys the original meaning and intent of the Chinese version. If deviations exist, I have provided explanatory comments to clarify the reasons.

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:

  • I have thoroughly reviewed the code, focusing on its formatting, comments, indentation, and file headers.
  • I have confirmed that the code execution outputs are consistent with those produced by the reference code (Python or Java).
  • The code is designed to be compatible on standard operating systems, including Windows, macOS, and Ubuntu.

result screenshot

Screenshot 2024-04-10 at 17 22 41

@krahets
Copy link
Owner

krahets commented Apr 10, 2024

Hi @juminhong, please complete the check list.

### 合并左子数组和右子数组 ###
def merge(nums, left, mid, right)
# 左子数组区间为 [left, mid], 右子数组区间为 [mid+1, right]
# 创建一个临时数组tmp,用于存放合并后的结果
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the comment in another PR.

(By the way, submitting your work in only one PR is fine.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

### 归并排序 ###
def merge_sort(nums, left, right)
# 终止条件
# 当子数组长度为1时终止递归
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

j += 1
k += 1
end
# 将临时数组tmp中的元素复制回原数组nums的对应区间
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@khoaxuantu khoaxuantu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @junminhong, I just have one small comment, the rest LGTM

codes/ruby/chapter_sorting/merge_sort.rb Outdated Show resolved Hide resolved
Co-authored-by: khoaxuantu <68913255+khoaxuantu@users.noreply.github.com>
Copy link
Contributor

@khoaxuantu khoaxuantu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @junminhong, could you help me change the code as the following:

codes/ruby/chapter_sorting/merge_sort.rb Outdated Show resolved Hide resolved
codes/ruby/chapter_sorting/merge_sort.rb Outdated Show resolved Hide resolved
codes/ruby/chapter_sorting/merge_sort.rb Outdated Show resolved Hide resolved
junminhong and others added 3 commits April 29, 2024 09:07
Co-authored-by: khoaxuantu <68913255+khoaxuantu@users.noreply.github.com>
Co-authored-by: khoaxuantu <68913255+khoaxuantu@users.noreply.github.com>
Co-authored-by: khoaxuantu <68913255+khoaxuantu@users.noreply.github.com>
Copy link
Contributor

@khoaxuantu khoaxuantu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Owner

@krahets krahets left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@krahets krahets merged commit 68f3a45 into krahets:main Apr 30, 2024
4 checks passed
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

Successfully merging this pull request may close these issues.

3 participants