Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 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 @@
|
|||
struct 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!(q::Queue{T}) where {T}
|
||||
!isempty(q) || error("queue must be non-empty")
|
||||
pop!(q.a)
|
||||
end
|
||||
|
||||
function Base.push!(q::Queue{T}, x::T) where {T}
|
||||
pushfirst!(q.a, x)
|
||||
return q
|
||||
end
|
||||
|
||||
function Base.push!(q::Queue{Any}, x::T) where {T}
|
||||
pushfirst!(q.a, x)
|
||||
return q
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue