Skip to content

Instantly share code, notes, and snippets.

@Rhernandez513
Created April 7, 2025 15:05
Show Gist options
  • Save Rhernandez513/20ee9fe3c239494efa39320109fb402c to your computer and use it in GitHub Desktop.
Save Rhernandez513/20ee9fe3c239494efa39320109fb402c to your computer and use it in GitHub Desktop.
python quicksort
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