Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
30
Task/Stack/E/stack-2.e
Normal file
30
Task/Stack/E/stack-2.e
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
def makeStack() {
|
||||
var store := null
|
||||
def stack {
|
||||
to push(x) { store := [x, store] }
|
||||
to pop() { def [x, next] := store; store := next; return x }
|
||||
to last() { return store[0] }
|
||||
to empty() { return (store == null) }
|
||||
}
|
||||
return stack
|
||||
}
|
||||
|
||||
? def s := makeStack()
|
||||
# value: <stack>
|
||||
|
||||
? s.push(1)
|
||||
? s.push(2)
|
||||
? s.last()
|
||||
# value: 2
|
||||
|
||||
? s.pop()
|
||||
# value: 2
|
||||
|
||||
? s.empty()
|
||||
# value: false
|
||||
|
||||
? s.pop()
|
||||
# value: 1
|
||||
|
||||
? s.empty()
|
||||
# value: true
|
||||
Loading…
Add table
Add a link
Reference in a new issue