Skip to content

Instantly share code, notes, and snippets.

@aspencer8111
Created March 13, 2017 15:01
Show Gist options
  • Save aspencer8111/0ea85304d5697cae680e96ea451c04b3 to your computer and use it in GitHub Desktop.
Save aspencer8111/0ea85304d5697cae680e96ea451c04b3 to your computer and use it in GitHub Desktop.
QuickSort added to array class
class Array
def quicksort
return [] if empty?
pivot = delete_at(rand(size))
left, right = partition(&pivot.method(:>))
return *left.quicksort, pivot, *right.quicksort
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment