Quick Sorting of Ruby Line Code Implementation

Time:2019-8-31

Copy codeThe code is as follows:
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]

Recommended Today

Laravel Tutorial – Practical Jam Community Open Source E-commerce API System

Important notice: The open source e-commerce version source code of Laravel + applet has been pulled on github, welcome to submit issue and star 🙂Open source e-commerce server:Laravel API source code Open source e-commerce client:applet source code Introduction to Jam Community IYOYO company was founded in Shanghai in 2011. After 8 years of industry accumulation, […]