Title / Description
Code def quicksort(array) return array if array.length <= 1 pivot_index = (array.length / 2).to_i pivot_value = array[pivot_index] array.delete_at(pivot_index) lesser = Array.new greater = Array.new array.each do |x| if x <= pivot_value lesser << x else greater << x end end return quicksort(lesser) + [pivot_value] + quicksort(greater) end names=[145, 125, 487, 2, 65, 10, 45, 78, 21] sorted_names = quicksort(names) puts sorted_names
Author
Highlight as C C++ CSS Clojure Delphi ERb Groovy (beta) HAML HTML JSON Java JavaScript PHP Plain text Python Ruby SQL XML YAML diff code