function BubbleSort(v::AbstractVector, lo::Int, hi::Int)
while true
clean = true
for i = lo:hi-1
if ( v[i+1]<v[i])
v[i+1], v[i] =v[i], v[i+1]
clean = false
end
end
clean && break
end
return v
end
#println("start")
println("氣泡排序算法")
v=rand(5)*10
println(v)
println("BubbleSort後的資料")
println(BubbleSort(v,1,5))
輸出結果
$julia main.jl
氣泡排序算法
[6.62896, 8.65323, 6.81813, 8.74972, 5.08322]
BubbleSort後的資料
[5.08322, 6.62896, 6.81813, 8.65323, 8.74972]
沒有留言:
張貼留言