Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1efbba8

Browse files
committed
归并排序添加注释
1 parent 8038332 commit 1efbba8

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

‎sort/src/main/java/com/mistray/merge/MergeSort.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,22 @@
66
* @author MistRay
77
* @create 2018年11月20日
88
* @desc 归并排序
9+
* 第一步:申请空间,使其大小为两个已经排序序列之和,该空间用来存放合并后的序列
10+
* 第二步:设定两个指针,最初位置分别为两个已经排序序列的起始位置
11+
* 第三步:比较两个指针所指向的元素,选择相对小的元素放入到合并空间,并移动指针到下一位置
12+
* 重复步骤3直到某一指针超出序列尾
13+
* 将另一序列剩下的所有元素直接复制到合并序列尾
914
*/
1015
public class MergeSort {
1116

1217
public static void main(String[] args) {
13-
int[] array = {35, 24, 86, 12, 95, 58, 35, 42, 21, 73};
18+
int[] array = {35, 24, 86, 12, 95, 58, 35, 42, 21, 73};
1419
sort(array, 0, array.length - 1);
1520
System.out.println(Arrays.toString(array));
1621
}
1722

18-
public static void sort(int[] array, int start, int end){
19-
if (start >= end){
23+
public static void sort(int[] array, int start, int end){
24+
if (start >= end){
2025
return;
2126
}
2227

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /