diff --git a/codes/c/chapter_sorting/quick_sort.c b/codes/c/chapter_sorting/quick_sort.c index 4268575a7..3441b8c01 100644 --- a/codes/c/chapter_sorting/quick_sort.c +++ b/codes/c/chapter_sorting/quick_sort.c @@ -52,7 +52,7 @@ void quickSort(int nums[], int left, int right) { /* 快速排序类(中位基准数优化) */ // 选取三个元素的中位数 int medianThree(int nums[], int left, int mid, int right) { - // 使用了异或操作来简化代码 + // 此处使用异或运算来简化代码 // 异或规则为 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1 if ((nums[left] < nums[mid]) ^ (nums[left] < nums[right])) return left; diff --git a/codes/cpp/chapter_sorting/quick_sort.cpp b/codes/cpp/chapter_sorting/quick_sort.cpp index e72691bc6..ebfda654b 100644 --- a/codes/cpp/chapter_sorting/quick_sort.cpp +++ b/codes/cpp/chapter_sorting/quick_sort.cpp @@ -57,7 +57,7 @@ private: /* 选取三个元素的中位数 */ static int medianThree(vector& nums, int left, int mid, int right) { - // 使用了异或操作来简化代码 + // 此处使用异或运算来简化代码 // 异或规则为 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1 if ((nums[left] < nums[mid]) ^ (nums[left] < nums[right])) return left; diff --git a/codes/csharp/chapter_sorting/quick_sort.cs b/codes/csharp/chapter_sorting/quick_sort.cs index 91b23b650..666ad73d5 100644 --- a/codes/csharp/chapter_sorting/quick_sort.cs +++ b/codes/csharp/chapter_sorting/quick_sort.cs @@ -63,7 +63,7 @@ class QuickSortMedian /* 选取三个元素的中位数 */ static int medianThree(int[] nums, int left, int mid, int right) { - // 使用了异或操作来简化代码 + // 此处使用异或运算来简化代码 // 异或规则为 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1 if ((nums[left] < nums[mid]) ^ (nums[left] < nums[right])) return left; diff --git a/codes/dart/chapter_sorting/quick_sort.dart b/codes/dart/chapter_sorting/quick_sort.dart index b0fd5b4e8..4dbcd5ad5 100644 --- a/codes/dart/chapter_sorting/quick_sort.dart +++ b/codes/dart/chapter_sorting/quick_sort.dart @@ -49,7 +49,7 @@ class QuickSortMedian { /* 选取三个元素的中位数 */ static int _medianThree(List nums, int left, int mid, int right) { - // 使用了异或操作来简化代码 + // 此处使用异或运算来简化代码 // 异或规则为 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1 if ((nums[left] < nums[mid]) ^ (nums[left] < nums[right])) return left; diff --git a/codes/go/chapter_sorting/quick_sort.go b/codes/go/chapter_sorting/quick_sort.go index ab7a2575c..66ea91dde 100644 --- a/codes/go/chapter_sorting/quick_sort.go +++ b/codes/go/chapter_sorting/quick_sort.go @@ -47,7 +47,7 @@ func (q *quickSort) quickSort(nums []int, left, right int) { /* 选取三个元素的中位数 */ func (q *quickSortMedian) medianThree(nums []int, left, mid, right int) int { - // 使用了异或操作来简化代码(!= 在这里起到异或的作用) + // 此处使用异或运算来简化代码(!= 在这里起到异或的作用) // 异或规则为 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1 if (nums[left] < nums[mid]) != (nums[left] < nums[right]) { return left diff --git a/codes/java/chapter_sorting/quick_sort.java b/codes/java/chapter_sorting/quick_sort.java index 16e84d51a..1fdf96a9e 100644 --- a/codes/java/chapter_sorting/quick_sort.java +++ b/codes/java/chapter_sorting/quick_sort.java @@ -56,7 +56,7 @@ class QuickSortMedian { /* 选取三个元素的中位数 */ static int medianThree(int[] nums, int left, int mid, int right) { - // 使用了异或操作来简化代码 + // 此处使用异或运算来简化代码 // 异或规则为 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1 if ((nums[left] < nums[mid]) ^ (nums[left] < nums[right])) return left; diff --git a/codes/javascript/chapter_sorting/quick_sort.js b/codes/javascript/chapter_sorting/quick_sort.js index 3915a178f..1ed445533 100644 --- a/codes/javascript/chapter_sorting/quick_sort.js +++ b/codes/javascript/chapter_sorting/quick_sort.js @@ -54,7 +54,7 @@ class QuickSortMedian { /* 选取三个元素的中位数 */ medianThree(nums, left, mid, right) { - // 使用了异或操作来简化代码 + // 此处使用异或运算来简化代码 // 异或规则为 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1 if ((nums[left] < nums[mid]) ^ (nums[left] < nums[right])) return left; else if ((nums[mid] < nums[left]) ^ (nums[mid] < nums[right])) return mid; diff --git a/codes/python/chapter_sorting/quick_sort.py b/codes/python/chapter_sorting/quick_sort.py index 75245b617..a41a23cac 100644 --- a/codes/python/chapter_sorting/quick_sort.py +++ b/codes/python/chapter_sorting/quick_sort.py @@ -40,11 +40,11 @@ class QuickSort: class QuickSortMedian: """ 选取三个元素的中位数 """ def median_three(self, nums, left, mid, right): - # 使用了异或操作来简化代码 + # 此处使用异或运算来简化代码 # 异或规则为 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1 if (nums[left] < nums[mid]) ^ (nums[left] < nums[right]): return left - elif (nums[mid] < nums[left]) ^ (nums[mid] > nums[right]): + elif (nums[mid] < nums[left]) ^ (nums[mid] < nums[right]): return mid return right diff --git a/codes/rust/chapter_sorting/quick_sort.rs b/codes/rust/chapter_sorting/quick_sort.rs index 875329073..d09652d45 100644 --- a/codes/rust/chapter_sorting/quick_sort.rs +++ b/codes/rust/chapter_sorting/quick_sort.rs @@ -47,7 +47,7 @@ impl QuickSort { impl QuickSortMedian { /* 选取三个元素的中位数 */ fn median_three(nums: &mut [i32], left: usize, mid: usize, right: usize) -> usize { - // 使用了异或操作来简化代码 + // 此处使用异或运算来简化代码 // 异或规则为 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1 if (nums[left] < nums[mid]) ^ (nums[left] < nums[right]) { return left; diff --git a/codes/typescript/chapter_sorting/quick_sort.ts b/codes/typescript/chapter_sorting/quick_sort.ts index 1f6de5a32..0ad57d8d8 100644 --- a/codes/typescript/chapter_sorting/quick_sort.ts +++ b/codes/typescript/chapter_sorting/quick_sort.ts @@ -56,7 +56,7 @@ class QuickSortMedian { /* 选取三个元素的中位数 */ medianThree(nums: number[], left: number, mid: number, right: number): number { - // 使用了异或操作来简化代码 + // 此处使用异或运算来简化代码 // 异或规则为 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1 if (Number(nums[left] < nums[mid]) ^ Number(nums[left] < nums[right])) { return left; diff --git a/codes/zig/chapter_sorting/quick_sort.zig b/codes/zig/chapter_sorting/quick_sort.zig index 2b1d92115..dee931da1 100644 --- a/codes/zig/chapter_sorting/quick_sort.zig +++ b/codes/zig/chapter_sorting/quick_sort.zig @@ -53,7 +53,7 @@ const QuickSortMedian = struct { // 选取三个元素的中位数 pub fn medianThree(nums: []i32, left: usize, mid: usize, right: usize) usize { - // 使用了异或操作来简化代码 + // 此处使用异或运算来简化代码 // 异或规则为 0 ^ 0 = 1 ^ 1 = 0, 0 ^ 1 = 1 ^ 0 = 1 if ((nums[left] < nums[mid]) != (nums[left] < nums[right])) { return left;