From e2ae907cd1ee3686fcb29ee98ddb347b34b3df8b Mon Sep 17 00:00:00 2001 From: machangxin Date: Mon, 12 Dec 2022 18:50:22 +0800 Subject: [PATCH] Insertion sort using go --- .../go/chapter_sorting/insertion_sort/insertion_sort.go | 9 ++++----- .../insertion_sort/insertion_sort_test.go | 9 ++++----- docs/chapter_sorting/insertion_sort.md | 7 +++---- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/codes/go/chapter_sorting/insertion_sort/insertion_sort.go b/codes/go/chapter_sorting/insertion_sort/insertion_sort.go index 47effeb75..235ae66fe 100644 --- a/codes/go/chapter_sorting/insertion_sort/insertion_sort.go +++ b/codes/go/chapter_sorting/insertion_sort/insertion_sort.go @@ -1,8 +1,7 @@ -/* - File: insertion_sort.go - Created Time: 2022-12-12 - Author: msk397 (machangxinq@gmail.com) -*/ +//File: insertion_sort.go +//Created Time: 2022-12-12 +//Author: msk397 (machangxinq@gmail.com) + package insertion_sort func insertionSort(nums []int) { diff --git a/codes/go/chapter_sorting/insertion_sort/insertion_sort_test.go b/codes/go/chapter_sorting/insertion_sort/insertion_sort_test.go index 1b37d6862..08f5cf771 100644 --- a/codes/go/chapter_sorting/insertion_sort/insertion_sort_test.go +++ b/codes/go/chapter_sorting/insertion_sort/insertion_sort_test.go @@ -1,8 +1,7 @@ -/* - File: insertion_sort_test.go - Created Time: 2022-12-12 - Author: msk397 (machangxinq@gmail.com) -*/ +//File: insertion_sort_test.go +//Created Time: 2022-12-12 +//Author: msk397 (machangxinq@gmail.com) + package insertion_sort import ( diff --git a/docs/chapter_sorting/insertion_sort.md b/docs/chapter_sorting/insertion_sort.md index 6edf060f5..c9be01c6b 100644 --- a/docs/chapter_sorting/insertion_sort.md +++ b/docs/chapter_sorting/insertion_sort.md @@ -87,13 +87,12 @@ comments: true j := i - 1 // 内循环:将 base 插入到左边的正确位置 for j >= 0 && nums[j] > base { - nums[j+1] = nums[j] // 1. 将 nums[j] 向右移动一位 + nums[j+1] = nums[j] // 1. 将 nums[j] 向右移动一位 j-- } - nums[j+1] = base // 2. 将 base 赋值到正确位置 + nums[j+1] = base // 2. 将 base 赋值到正确位置 } -} - + } ``` === "JavaScript"