all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
|
|
@ -0,0 +1,9 @@
|
|||
class Array
|
||||
def quick_sort
|
||||
return self if length <= 1
|
||||
pivot = self[length / 2]
|
||||
find_all { |i| i < pivot }.quick_sort +
|
||||
find_all { |i| i == pivot } +
|
||||
find_all { |i| i > pivot }.quick_sort
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue