Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
20
Task/Stack/Jq/stack-1.jq
Normal file
20
Task/Stack/Jq/stack-1.jq
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# create a Stack
|
||||
def Stack: {stack: []};
|
||||
|
||||
# check an object is a Stack
|
||||
def isStack:
|
||||
type == "object" and has("stack") and (.stack|type) == "array";
|
||||
|
||||
def pop:
|
||||
if .stack|length == 0 then "pop: stack is empty" | error
|
||||
else {stack: .stack[1:], item: .stack[0]]
|
||||
end;
|
||||
|
||||
def push($x):
|
||||
.stack = [$x] + .stack | .item = null;
|
||||
|
||||
def size:
|
||||
.stack | length;
|
||||
|
||||
def isEmpty:
|
||||
size == 0;
|
||||
Loading…
Add table
Add a link
Reference in a new issue