This commit is contained in:
krahets
2024-05-24 16:12:17 +08:00
parent e434a3343c
commit 6bac0db1c4
22 changed files with 635 additions and 99 deletions

View File

@@ -99,7 +99,7 @@ The implementation of merge sort is shown in the following code. Note that the i
if left >= right:
return # Terminate recursion when subarray length is 1
# Partition stage
mid = (left + right) // 2 # Calculate midpoint
mid = left + (right - left) // 2 # Calculate midpoint
merge_sort(nums, left, mid) # Recursively process the left subarray
merge_sort(nums, mid + 1, right) # Recursively process the right subarray
# Merge stage
@@ -142,7 +142,7 @@ The implementation of merge sort is shown in the following code. Note that the i
if (left >= right)
return; // Terminate recursion when subarray length is 1
// Partition stage
int mid = (left + right) / 2; // Calculate midpoint
int mid = left + (right - left) / 2; // Calculate midpoint
mergeSort(nums, left, mid); // Recursively process the left subarray
mergeSort(nums, mid + 1, right); // Recursively process the right subarray
// Merge stage
@@ -186,7 +186,7 @@ The implementation of merge sort is shown in the following code. Note that the i
if (left >= right)
return; // Terminate recursion when subarray length is 1
// Partition stage
int mid = (left + right) / 2; // Calculate midpoint
int mid = left + (right - left) / 2; // Calculate midpoint
mergeSort(nums, left, mid); // Recursively process the left subarray
mergeSort(nums, mid + 1, right); // Recursively process the right subarray
// Merge stage