Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
13
Task/Queue-Definition/Erlang/queue-definition.erl
Normal file
13
Task/Queue-Definition/Erlang/queue-definition.erl
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
-module(fifo).
|
||||
-export([new/0, push/2, pop/1, empty/1]).
|
||||
|
||||
new() -> {fifo, [], []}.
|
||||
|
||||
push({fifo, In, Out}, X) -> {fifo, [X|In], Out}.
|
||||
|
||||
pop({fifo, [], []}) -> erlang:error('empty fifo');
|
||||
pop({fifo, In, []}) -> pop({fifo, [], lists:reverse(In)});
|
||||
pop({fifo, In, [H|T]}) -> {H, {fifo, In, T}}.
|
||||
|
||||
empty({fifo, [], []}) -> true;
|
||||
empty({fifo, _, _}) -> false.
|
||||
Loading…
Add table
Add a link
Reference in a new issue