Time for an 2014 update…
This commit is contained in:
parent
372c577f83
commit
09687c4926
2520 changed files with 34227 additions and 7318 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue