Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
24
Task/Queue-Definition/Julia/queue-definition.julia
Normal file
24
Task/Queue-Definition/Julia/queue-definition.julia
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
type Queue{T}
|
||||
a::Array{T,1}
|
||||
end
|
||||
|
||||
Queue() = Queue(Any[])
|
||||
Queue(a::DataType) = Queue(a[])
|
||||
Queue(a) = Queue(typeof(a)[])
|
||||
|
||||
Base.isempty(q::Queue) = isempty(q.a)
|
||||
|
||||
function Base.pop!{T}(q::Queue{T})
|
||||
!isempty(q) || error("queue must be non-empty")
|
||||
pop!(q.a)
|
||||
end
|
||||
|
||||
function Base.push!{T}(q::Queue{T}, x::T)
|
||||
unshift!(q.a, x)
|
||||
return q
|
||||
end
|
||||
|
||||
function Base.push!{T}(q::Queue{Any}, x::T)
|
||||
unshift!(q.a, x)
|
||||
return q
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue