66 lines
1.5 KiB
Plaintext
66 lines
1.5 KiB
Plaintext
/* NetRexx */
|
|
options replace format comments java crossref savelog symbols nobinary
|
|
|
|
-- Queue Usage Demonstration Program -------------------------------------------
|
|
method main(args = String[]) public constant
|
|
kew = RCQueueImpl()
|
|
do
|
|
say kew.pop()
|
|
catch ex = IndexOutOfBoundsException
|
|
say ex.getMessage
|
|
say
|
|
end
|
|
|
|
melancholyDane = ''
|
|
melancholyDane[0] = 4
|
|
melancholyDane[1] = 'To be'
|
|
melancholyDane[2] = 'or'
|
|
melancholyDane[3] = 'not to be?'
|
|
melancholyDane[4] = 'That is the question.'
|
|
|
|
loop p_ = melancholyDane[0] to 1 by -1
|
|
kew.push(melancholyDane[p_])
|
|
end p_
|
|
|
|
loop while \kew.empty
|
|
popped = kew.pop
|
|
say popped '\-'
|
|
end
|
|
say; say
|
|
|
|
-- demonstrate stowing something other than a text string in the queue
|
|
kew.push(melancholyDane)
|
|
md = kew.pop
|
|
loop l_ = 1 to md[0]
|
|
say md[l_] '\-'
|
|
end l_
|
|
say
|
|
|
|
return
|
|
|
|
-- Queue implementation --------------------------------------------------------
|
|
class RCQueueImpl
|
|
properties private
|
|
qqq = Deque
|
|
|
|
method RCQueueImpl() public
|
|
qqq = ArrayDeque()
|
|
return
|
|
|
|
method push(stuff) public
|
|
qqq.push(stuff)
|
|
return
|
|
|
|
method pop() public returns Rexx signals IndexOutOfBoundsException
|
|
if qqq.isEmpty then signal IndexOutOfBoundsException('The queue is empty')
|
|
return Rexx qqq.pop()
|
|
|
|
method empty() public binary returns boolean
|
|
return qqq.isEmpty
|
|
|
|
method isTrue public constant binary returns boolean
|
|
return 1 == 1
|
|
|
|
method isFalse public constant binary returns boolean
|
|
return \isTrue
|