June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -0,0 +1,62 @@
import extensions.
template queue :: type
{
array<type> theArray.
int theTop.
int theTale.
explicit
[
theArray := type<>(8).
theTop := 0.
theTale := 0.
]
bool empty
= theTop == theTale.
push type:anObject
[
if (theTale > theArray length)
[
theArray := theArray reallocate(theTale).
].
theArray[theTale] := anObject.
theTale += 1.
]
type pop
[
if (theTale == theTop)
[ InvalidOperationException new:"Queue is empty"; raise ].
type item := theArray[theTop].
theTop += 1.
^ item
]
}
program =
[
queue<int> q := queue<int>().
q push(1).
q push(2).
q push(3).
console printLine(q pop).
console printLine(q pop).
console printLine(q pop).
console printLine("a queue is ", q empty; iif("empty","not empty")).
console print("Trying to pop:").
try(q pop)
{
on(Exception e)
[
console printLine(e message)
]
}
].