Skip to content

Instantly share code, notes, and snippets.

@PJK
Created November 4, 2011 17:54
Show Gist options
  • Save PJK/1340007 to your computer and use it in GitHub Desktop.
Save PJK/1340007 to your computer and use it in GitHub Desktop.
Ruby quicksort
#!/usr/bin/env ruby
data = Array.new
50.times { data << rand(100) }
def qs(list)
return list if list.length < 2
smaller, bigger = list[1..-1].partition {|x| x < list[0] }
return qs(smaller) + [list[0]] + qs(bigger)
end
puts qs(data).inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment