Revision 294b253e29336ae943f91c4c62730236c3f3259c authored by Sacha Verweij on 10 March 2017, 04:43:27 UTC, committed by Sacha Verweij on 10 March 2017, 17:58:56 UTC
1 parent 4521e6b
Raw File
bubblesort.jl
# This file is a part of Julia. License is MIT: http://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
back to top