RosettaCodeData/Task/Queue-Definition/Smalltalk/queue-definition.st

21 lines
431 B
Smalltalk
Raw Permalink Normal View History

2013-04-10 23:57:08 -07:00
OrderedCollection extend [
push: obj [ ^(self add: obj) ]
pop [
(self isEmpty) ifTrue: [
SystemExceptions.NotFound signalOn: self
reason: 'queue empty'
] ifFalse: [
^(self removeFirst)
]
]
]
|f|
f := OrderedCollection new.
f push: 'example'; push: 'another'; push: 'last'.
f pop printNl.
f pop printNl.
f pop printNl.
f isEmpty printNl.
f pop. "queue empty error"