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,21 @@
|
|||
function pancakesort!{T<:Real}(a::Array{T,1})
|
||||
len = length(a)
|
||||
if len < 2
|
||||
return a
|
||||
end
|
||||
for i in len:-1:2
|
||||
j = indmax(a[1:i])
|
||||
i != j || continue
|
||||
a[1:j] = reverse(a[1:j])
|
||||
a[1:i] = reverse(a[1:i])
|
||||
end
|
||||
return a
|
||||
end
|
||||
|
||||
pancakesort{T<:Real}(a::Array{T,1}) = pancakesort!(copy(a))
|
||||
|
||||
println("Testing a pancake sort.")
|
||||
a = [rand(-100:100) for i in 1:20]
|
||||
println("Pre: ", a)
|
||||
b = pancakesort(a)
|
||||
println("Post: ", b)
|
||||
Loading…
Add table
Add a link
Reference in a new issue