Skip to content

Instantly share code, notes, and snippets.

@DenKey
Last active November 8, 2023 18:28
Show Gist options
  • Save DenKey/1ea793cf05f05fd2f3f1de1835e2251d to your computer and use it in GitHub Desktop.
Save DenKey/1ea793cf05f05fd2f3f1de1835e2251d to your computer and use it in GitHub Desktop.
Quicksort
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