Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -0,0 +1,25 @@
|
|||
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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue