Time for an 2014 update…

This commit is contained in:
Ingy döt Net 2014-01-17 05:32:22 +00:00
parent 372c577f83
commit 09687c4926
2520 changed files with 34227 additions and 7318 deletions

View file

@ -1,7 +1,7 @@
class Array
def quick_sort
return self if length <= 1
pivot = self[length / 2]
pivot = sample
find_all { |i| i < pivot }.quick_sort +
find_all { |i| i == pivot } +
find_all { |i| i > pivot }.quick_sort

View file

@ -3,8 +3,6 @@ class Array
return self if length <= 1
pivot = self[0]
less, greatereq = self[1..-1].partition { |x| x < pivot }
less.quick_sort +
[pivot] +
greatereq.quick_sort
less.quick_sort + [pivot] + greatereq.quick_sort
end
end

View file

@ -0,0 +1,9 @@
class Array
def quick_sort
return self if length <= 1
pivot = sample
group = group_by{ |x| x <=> pivot }
group.default = []
group[-1].quick_sort + group[0] + group[1].quick_sort
end
end