Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
16
Task/Stack/Icon/stack.icon
Normal file
16
Task/Stack/Icon/stack.icon
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
procedure main()
|
||||
stack := [] # new empty stack
|
||||
push(stack,1) # add item
|
||||
push(stack,"hello",table(),set(),[],5) # add more items of mixed types in order left to right
|
||||
y := top(stack) # peek
|
||||
x := pop(stack) # remove item
|
||||
write("The stack is ",if isempty(stack) then "empty" else "not empty")
|
||||
end
|
||||
|
||||
procedure isempty(x) #: test if a datum is empty, return the datum or fail (task requirement)
|
||||
if *x = 0 then return x # in practice just write *x = 0 or *x ~= 0 for is/isn't empty
|
||||
end
|
||||
|
||||
procedure top(x) #: return top element w/o changing stack
|
||||
return x[1] # in practice, just use x[1]
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue