Skip to content

Instantly share code, notes, and snippets.

@cdollins
Created January 27, 2010 17:19
Show Gist options
  • Save cdollins/288019 to your computer and use it in GitHub Desktop.
Save cdollins/288019 to your computer and use it in GitHub Desktop.
class Quick
def self.sort(array)
return array if array.size < 2
lesser = []
greater = []
pivot = array.pop
array.each do |x|
x <= pivot ? lesser << x : greater << x
end
self.sort(lesser) + [pivot]+ self.sort(greater)
end
end
class Quick
def self.sort(array)
return array if array.size < 2
pivot = array.pop
array = array.partition { |x| x <= pivot }
self.sort(array.first) + [pivot] + self.sort(array.last)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment