Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -1,9 +1,8 @@
class Array
def quick_sort
return self if length <= 1
pivot = sample
find_all { |i| i < pivot }.quick_sort +
find_all { |i| i == pivot } +
find_all { |i| i > pivot }.quick_sort
pivot = self[0]
less, greatereq = self[1..-1].partition { |x| x < pivot }
less.quick_sort + [pivot] + greatereq.quick_sort
end
end

View file

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

View file

@ -1,9 +1,6 @@
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
h, *t = self
h ? t.partition { |e| e < h }.inject { |l, r| l.quick_sort + [h] + r.quick_sort } : []
end
end