Created
January 31, 2023 16:35
-
-
Save Aleksey-Danchin/d8a5c4eda2beddb32521046910e35958 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def quick_sort(array: list): | |
def quick_sort_master(start_index, finish_index): | |
pivot = array[(start_index + finish_index) // 2] | |
left_index = start_index | |
right_index = finish_index | |
while left_index <= right_index: | |
while array[left_index] < pivot: | |
left_index += 1 | |
while array[right_index] > pivot: | |
right_index -= 1 | |
if left_index <= right_index: | |
[ | |
array[left_index], | |
array[right_index] | |
] = [ | |
array[right_index], | |
array[left_index] | |
] | |
left_index += 1 | |
right_index -= 1 | |
print(array) | |
if start_index < left_index - 1: | |
quick_sort_master(start_index, left_index - 1) | |
if left_index < finish_index: | |
quick_sort_master(left_index, finish_index) | |
quick_sort_master(0, len(array) - 1) | |
return array |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment