Created
February 14, 2022 11:28
-
-
Save krypton-byte/89fec4d51c604f68a6ae7c7564109955 to your computer and use it in GitHub Desktop.
Quick Sort Algorithm
This file contains hidden or 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 Generator | |
| def quick_sort(sequence: list) -> Generator: | |
| if sequence.__len__() <= 1: | |
| yield from sequence | |
| else: | |
| low = [] | |
| high = [] | |
| pivot = sequence.pop() | |
| for i in sequence: | |
| [low, high][i > pivot].append(i) | |
| yield from quick_sort(low) | |
| yield pivot | |
| yield from quick_sort(high) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment