Add: julia-0.6.2
Former-commit-id: ccc667cf67d569f3fb3df39aa57c2134755a7551
This commit is contained in:
19
julia-0.6.2/share/doc/julia/examples/bubblesort.jl
Normal file
19
julia-0.6.2/share/doc/julia/examples/bubblesort.jl
Normal file
@@ -0,0 +1,19 @@
|
||||
# This file is a part of Julia. License is MIT: https://julialang.org/license
|
||||
|
||||
import Base.Sort
|
||||
struct BubbleSortAlg <: Sort.Algorithm end
|
||||
const BubbleSort = BubbleSortAlg()
|
||||
|
||||
function Base.sort!(v::AbstractVector, lo::Int, hi::Int, ::BubbleSortAlg, o::Sort.Ordering)
|
||||
while true
|
||||
clean = true
|
||||
for i = lo:hi-1
|
||||
if Sort.lt(o, 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
|
||||
Reference in New Issue
Block a user