欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Ruby一行代碼實(shí)現(xiàn)的快速排序

 更新時間:2015年05月22日 10:55:01   投稿:junjie  
這篇文章主要介紹了Ruby一行代碼實(shí)現(xiàn)的快速排序,本文直接給出實(shí)現(xiàn)代碼,超級簡潔的一個的方法,需要的朋友可以參考下

復(fù)制代碼 代碼如下:

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]

相關(guān)文章

最新評論