#! /usr/bin/julia

# Rosetta Code, Sorting algorithms/Bubble sort

function bubblesort{T}(a::AbstractArray{T,1})
    b = copy(a)
    isordered = false
    span = length(b)
    while !isordered && span > 1
        isordered = true
        for i in 2:span
            if b[i] < b[i-1]
                t = b[i]
                b[i] = b[i-1]
                b[i-1] = t
                isordered = false
            end
        end
        span -= 1
    end
    return b
end

a = [rand(-100:100) for i in 1:20]
println("Before bubblesort:")
println(a)
a = bubblesort(a)
println("\nAfter bubblesort:")
println(a)

