Skip to content

Instantly share code, notes, and snippets.

@KerryJones
Created July 28, 2020 04:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KerryJones/3df6601c2116e83f7edcc02f1638e9eb to your computer and use it in GitHub Desktop.
Save KerryJones/3df6601c2116e83f7edcc02f1638e9eb to your computer and use it in GitHub Desktop.
from typing import List
def quick_sort(array: List, start: int, end: int) -> None:
if start >= end:
return
pivot = partition(array, start, end)
quick_sort(array, start, pivot - 1)
quick_sort(array, pivot + 1, end)
def partition(array: List, start: int, end: int) -> int:
pivot = start
for i in range(start, end):
if array[i] < array[end]:
array[i], array[pivot] = array[pivot], array[i]
pivot += 1
array[pivot], array[end] = array[end], array[pivot]
return pivot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment