Skip to content

Instantly share code, notes, and snippets.

@hrdavis
Created December 15, 2014 03:30
Show Gist options
  • Save hrdavis/616742d05803bc443b51 to your computer and use it in GitHub Desktop.
Save hrdavis/616742d05803bc443b51 to your computer and use it in GitHub Desktop.
QUICKSORT( A, left, right )
if left < right
pivot = PARTITION( A, left, right )
QUICKSORT( A, left, pivot - 1 )
QUICKSORT( A, pivot + 1, right )
PARTITION( A, left, right )
pivot = A[ right ]
i = left - 1
for j = left to right - 1
if A[ j ] <= pivot
i = i + 1
swap A[ i ] with A[ j ]
swap A[ i + 1 ] with A[ right ]
return i + 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment