Skip to content

Instantly share code, notes, and snippets.

@Mez0
Created May 10, 2018 12:41
Show Gist options
  • Save Mez0/2eca860855666a1177f4984c312ee1e4 to your computer and use it in GitHub Desktop.
Save Mez0/2eca860855666a1177f4984c312ee1e4 to your computer and use it in GitHub Desktop.
def quicksort(a)
return a unless a.count > 1
pivot = a[0]
less = a.select {|num| num < pivot }
equal = a.select {|num| num == pivot }
greater = a.select {|num| num > pivot }
return quicksort(less) + equal + quicksort(greater)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment