Last active
November 8, 2023 18:28
-
-
Save DenKey/1ea793cf05f05fd2f3f1de1835e2251d to your computer and use it in GitHub Desktop.
Quicksort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def quicksort(array) | |
if array.size < 2 | |
return array | |
else | |
pivot = array[0] | |
less = array[1..-1].filter {|item| item <= pivot } | |
greater = array[1..-1].filter {|item| item > pivot} | |
return quicksort(less) + pivot + quicksort(greater) | |
end | |
end | |
puts quicksort([4,3,6,78,5,3,1,4,6,7,3432,434343,3,5,6,7,9]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment