Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -25,7 +25,9 @@ void enqueue(queue q, DATA n)
|
|||
{
|
||||
if (q->tail >= q->alloc) q->tail = 0;
|
||||
q->buf[q->tail++] = n;
|
||||
if (q->tail == q->head) { /* needs more room */
|
||||
|
||||
// Fixed bug where it failed to resizes
|
||||
if (q->tail == q->alloc) { /* needs more room */
|
||||
q->buf = realloc(q->buf, sizeof(DATA) * q->alloc * 2);
|
||||
if (q->head) {
|
||||
memcpy(q->buf + q->head + q->alloc, q->buf + q->head,
|
||||
|
|
|
|||
12
Task/Queue-Definition/Elixir/queue-definition.elixir
Normal file
12
Task/Queue-Definition/Elixir/queue-definition.elixir
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
defmodule Queue do
|
||||
def new, do: {Queue, [], []}
|
||||
|
||||
def push({Queue, input, output}, x), do: {Queue, [x|input], output}
|
||||
|
||||
def pop({Queue, [], []}), do: (raise RuntimeError, message: "empty Queue")
|
||||
def pop({Queue, input, []}), do: pop({Queue, [], Enum.reverse(input)})
|
||||
def pop({Queue, input, [h|t]}), do: {h, {Queue, input, t}}
|
||||
|
||||
def empty?({Queue, [], []}), do: true
|
||||
def empty?({Queue, _, _}), do: false
|
||||
end
|
||||
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