September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
10
Task/Queue-Definition/Jq/queue-definition-1.jq
Normal file
10
Task/Queue-Definition/Jq/queue-definition-1.jq
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
# An empty queue:
|
||||
def fifo: [];
|
||||
|
||||
def push(e): [e] + .;
|
||||
|
||||
def pop: [.[0], .[1:]];
|
||||
|
||||
def pop_or_error: if length == 0 then error("pop_or_error") else pop end;
|
||||
|
||||
def empty: length == 0;
|
||||
13
Task/Queue-Definition/Jq/queue-definition-2.jq
Normal file
13
Task/Queue-Definition/Jq/queue-definition-2.jq
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
fifo | pop # produces [null,[]]
|
||||
|
||||
fifo
|
||||
| push(42) # enqueue
|
||||
| push(43) # enqueue
|
||||
| pop # dequeue
|
||||
| .[0] # the value
|
||||
# produces 43
|
||||
|
||||
fifo|push(1) as $q1
|
||||
| fifo|push(2) as $q2
|
||||
| [($q1|pop|.[0]), ($q2|pop|.[0])]
|
||||
# produces: [1, 2]
|
||||
Loading…
Add table
Add a link
Reference in a new issue