enh(Python): rename from insertionSort_rec to insertion_sort_rec (#669)

pull/540/head^2
Alim Kerem Erdoğmuş 2022-01-13 15:55:32 +03:00 committed by GitHub
parent fd9f7b4806
commit 110518e7c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 14 deletions

View File

@ -4,16 +4,15 @@ Recursively sort first n-1 elements.
Insert last element at its correct position in sorted array.
"""
def insertionSort_rec(array, n):
# base case
if n <= 1:
def insertion_sort_rec(array, length_arr):
"""Base Case"""
if length_arr <= 1:
return
# Sort first n-1 elements
insertionSort_rec(array, n-1)
'''Insert last element at its correct position
in sorted array.'''
end = array[n-1]
j = n-2
insertion_sort_rec(array, length_arr-1)
# Insert last element at its correct position in sorted array.
end = array[length_arr-1]
j = length_arr-2
# Move elements of arr[0..i-1], that are
# greater than key, to one position ahead
@ -23,8 +22,8 @@ def insertionSort_rec(array, n):
j -= 1
array[j+1] = end
arr = [6, 5, 2, 7, 12, 9, 1, 4]
insertionSort_rec(arr, len(arr))
print("Sorted array is:")
print(arr)
if __name__ == '__main__':
arr = [6, 5, 2, 7, 12, 9, 1, 4]
insertion_sort_rec(arr, len(arr))
print("Sorted array is:")
print(arr)