Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,8 @@
|
|||
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
|
||||
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
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
class Array
|
||||
def 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