@ -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;
@ -57,7 +57,7 @@ private:
/* 选取三个元素的中位数 */
static int medianThree(vector<int>& nums, int left, int mid, int right) {
@ -63,7 +63,7 @@ class QuickSortMedian
static int medianThree(int[] nums, int left, int mid, int right)
{
@ -49,7 +49,7 @@ class QuickSortMedian {
static int _medianThree(List<int> nums, int left, int mid, int right) {
@ -47,7 +47,7 @@ func (q *quickSort) quickSort(nums []int, left, right int) {
func (q *quickSortMedian) medianThree(nums []int, left, mid, right int) int {
// 使用了异或操作来简化代码(!= 在这里起到异或的作用)
// 此处使用异或运算来简化代码(!= 在这里起到异或的作用)
if (nums[left] < nums[mid]) != (nums[left] < nums[right]) {
return left
@ -56,7 +56,7 @@ class QuickSortMedian {
static int medianThree(int[] nums, int left, int mid, int right) {
@ -54,7 +54,7 @@ class QuickSortMedian {
medianThree(nums, left, mid, right) {
if ((nums[left] < nums[mid]) ^ (nums[left] < nums[right])) return left;
else if ((nums[mid] < nums[left]) ^ (nums[mid] < nums[right])) return mid;
@ -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]):
elif (nums[mid] < nums[left]) ^ (nums[mid] > nums[right]):
elif (nums[mid] < nums[left]) ^ (nums[mid] < nums[right]):
return mid
return right
@ -47,7 +47,7 @@ impl QuickSort {
impl QuickSortMedian {
fn median_three(nums: &mut [i32], left: usize, mid: usize, right: usize) -> usize {
if (nums[left] < nums[mid]) ^ (nums[left] < nums[right]) {
medianThree(nums: number[], left: number, mid: number, right: number): number {
if (Number(nums[left] < nums[mid]) ^ Number(nums[left] < nums[right])) {
@ -53,7 +53,7 @@ const QuickSortMedian = struct {
pub fn medianThree(nums: []i32, left: usize, mid: usize, right: usize) usize {
if ((nums[left] < nums[mid]) != (nums[left] < nums[right])) {