June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -1,25 +1,9 @@
|
|||
function isordered{T}(a::AbstractArray{T,1})
|
||||
if length(a) < 2
|
||||
return true
|
||||
function bogosort!(arr::AbstractVector)
|
||||
while !issorted(arr)
|
||||
shuffle!(arr)
|
||||
end
|
||||
for i in 2:length(a)
|
||||
if a[i] < a[i-1]
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
return arr
|
||||
end
|
||||
|
||||
function bogosort!{T}(a::AbstractArray{T,1})
|
||||
while !isordered(a)
|
||||
shuffle!(a)
|
||||
end
|
||||
return a
|
||||
end
|
||||
|
||||
a = [rand(-10:10) for i in 1:10]
|
||||
println("Before bogosort:")
|
||||
println(a)
|
||||
bogosort!(a)
|
||||
println("\nAfter bogosort:")
|
||||
println(a)
|
||||
v = rand(-10:10, 10)
|
||||
println("# unordered: $v\n -> ordered: ", bogosort!(v))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue