Skip to content

Instantly share code, notes, and snippets.

@egrueter-dev
Created February 24, 2015 22:41
Show Gist options
  • Save egrueter-dev/380bf3b2cf63fc8e5e7a to your computer and use it in GitHub Desktop.
Save egrueter-dev/380bf3b2cf63fc8e5e7a to your computer and use it in GitHub Desktop.
Quick-sort Algorithm
def quick_sort(arr)
return arr if arr.length <= 1
pivot = arr.pop
less_than_pivot = arr.select { |x| x < pivot }
greater_than_pivot = arr.select { |x| x > pivot }
quick_sort(less_than_pivot) + [pivot] + quick_sort(greater_than_pivot)
end
print quick_sort([1,5,9,2,45,2,3,4,4545])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment