def quick_sort(a)
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]
def quick_sort(a)
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]

2023-03-10
0万阅读

2023-03-10
0万阅读

2023-03-05
0万阅读

2023-03-03
0万阅读

2023-02-21
6万阅读

2023-02-12
9万阅读

2023-01-14
2万阅读

2023-01-07
2万阅读

2023-01-06
6万阅读

2023-01-04
2万阅读

2023-03-10
0万阅读

2023-03-10
0万阅读

2023-03-05
0万阅读

2023-03-03
0万阅读

2023-02-21
6万阅读

2023-02-12
9万阅读

2023-01-14
2万阅读

2023-01-07
2万阅读

2023-01-06
6万阅读

2023-01-04
2万阅读