Skip to content

Commit 9c5f477

Browse files
committed
update merge sort
1 parent 7ef14f9 commit 9c5f477

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

5_merge_sort.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ package algorithm
22

33
// MergeSort ..
44
// No.5
5+
// 归并排序(稳定)算法步骤:
6+
// 1. 申请空间,使其大小为两个已经排序序列之和,该空间用来存放合并后的序列;
7+
// 2. 设定两个指针,最初位置分别为两个已经排序序列的起始位置;
8+
// 3. 比较两个指针所指向的元素,选择相对小的元素放入到合并空间,并移到指针到下一位置;
9+
// 4. 重复步骤3直到某一指针达到序列尾;
10+
// 5. 将另一序列剩下的所有元素直接复制到合并序列尾。
511
func mergeSort(arr []int) []int {
612
length := len(arr)
713
if length < 2 {

0 commit comments

Comments
 (0)