您的位置:首页 > 编程语言 > Ruby

Ruby学习之路——编程实践【5】 选择排序

2012-06-08 11:25 295 查看
Ruby学习之路——编程实践【5】  2012-06-08

选择排序

def selectSort(arrInt, low = 0, high = arrInt.length - 1)
0.upto(high - 1) do |i|
small = i
i.upto(high) do |j|
if arrInt[j] < arrInt[small] then
small = j
end
end
if small != i then
arrInt[small], arrInt[i] = arrInt[i], arrInt[small]
end
end
end
a = Array.new
0.upto(100){ |i| a[a.length] = (Random.new.rand*10**2).to_i }
selectSort(a)
p a


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ruby 编程
相关文章推荐