Created
April 7, 2025 15:05
-
-
Save Rhernandez513/20ee9fe3c239494efa39320109fb402c to your computer and use it in GitHub Desktop.
python quicksort
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
| def qs(arr): | |
| if not arr: | |
| return [] | |
| len_arr = len(arr) | |
| if len_arr <= 1: | |
| return arr | |
| xs = arr[0] | |
| smaller = [x for x in arr[1:] if x <= xs] | |
| larger = [x for x in arr[1:] if x > xs] | |
| return qs(smaller) + [xs] + qs(larger) | |
| a = [12, 1, 0 ,3, 1, 5, 3 ,1, 5, -1, 131, 2, 9] | |
| print(qs(a)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment