Last active
December 4, 2020 21:06
-
-
Save Madoshakalaka/dc0fca1b6226d2c255a582f801a5a1fd 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
from typing import List | |
def quick_sort_find_n_th_largest(numbers: List[float], n: int) -> float: | |
pivot = numbers[0] | |
left = [] | |
right = [] | |
for num in numbers[1:]: | |
if num >= pivot: | |
left.append(num) | |
else: | |
right.append(num) | |
len_left = len(left) | |
diff = n - len_left | |
if diff > 1: | |
return quick_sort_find_n_th_largest(right, diff-1) | |
elif diff == 1: | |
return pivot | |
else: | |
return quick_sort_find_n_th_largest(left, n) | |
list_1 = [1,2,3,4,5,6,7,8,] | |
print(quick_sort_find_n_th_largest(list_1, 1)) | |
print(quick_sort_find_n_th_largest(list_1, 2)) | |
print(quick_sort_find_n_th_largest(list_1, 3)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment