Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue