Skip to content

Commit f087db3

Browse files
author
Benjamin Fein
committed
Fixes variable names to use snake_case.
1 parent 751e9b8 commit f087db3

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

sorts/recursive_mergesort_array.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ def merge(arr: list[int]) -> list[int]:
1111
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
1212
>>> merge([10,22,1,2,3,9,15,23])
1313
[1, 2, 3, 9, 10, 15, 22, 23]
14+
>>> merge([100])
15+
[100]
16+
>>> merge([])
17+
[]
1418
"""
1519
if len(arr) > 1:
1620
middle_length = len(arr) // 2 ##Finds the middle of the array
@@ -24,30 +28,30 @@ def merge(arr: list[int]) -> list[int]:
2428
right_size = len(right_array)
2529
merge(left_array) ## Starts sorting the left.
2630
merge(right_array) ##Starts sorting the right
27-
leftIndex = 0 ##Left Counter
28-
rightIndex = 0 ## Right Counter
31+
left_index = 0 ##Left Counter
32+
right_index = 0 ## Right Counter
2933
index = 0 ## Position Counter
3034
while (
31-
leftIndex < left_size and rightIndex < right_size
35+
left_index < left_size and right_index < right_size
3236
): ##Runs until the lowers size of the left and right are sorted.
33-
if left_array[leftIndex] < right_array[rightIndex]:
34-
arr[index] = left_array[leftIndex]
35-
leftIndex = leftIndex + 1
37+
if left_array[left_index] < right_array[right_index]:
38+
arr[index] = left_array[left_index]
39+
left_index = left_index + 1
3640
else:
37-
arr[index] = right_array[rightIndex]
38-
rightIndex = rightIndex + 1
41+
arr[index] = right_array[right_index]
42+
right_index = right_index + 1
3943
index = index + 1
4044
while (
41-
leftIndex < left_size
45+
left_index < left_size
4246
): ##Adds the left over elements in the left half of the array
43-
arr[index] = left_array[leftIndex]
44-
leftIndex = leftIndex + 1
47+
arr[index] = left_array[left_index]
48+
left_index = left_index + 1
4549
index = index + 1
4650
while (
47-
rightIndex < right_size
51+
right_index < right_size
4852
): ##Adds the left over elements in the right half of the array
49-
arr[index] = right_array[rightIndex]
50-
rightIndex = rightIndex + 1
53+
arr[index] = right_array[right_index]
54+
right_index = right_index + 1
5155
index = index + 1
5256
return arr
5357

0 commit comments

Comments
 (0)