Queue/Definition: Difference between revisions

Line 1,331:
</lang>
=={{header|Elena}}==
ELENA 3.2.13 :
<lang elena>import extensions.
 
template queue :: type
{
Line 1,339:
int theTop.
int theTale.
explicit
[
theArray := type&<>(8).
theTop := 0.
theTale := 0.
]
bool empty
= theTop == theTale.
push type:anObject
[
Line 1,356:
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).
Anonymous user