时间:2021-02-23 15:15:31 | 栏目:Ruby | 点击:次
return a if a.size < 2
(x = a.pop) ? quick_sort(a.select{|i| i <=x }) + [x] + quick_sort(a.select{|i| i > x}) : []
end
array = [72,6,57,88,60,42,83,73,42,48,85]
p quick_sort(array) #=> [6, 42, 42, 48, 57, 60, 72, 73, 83, 85, 88]