
Collection subclass: #Stack
  instanceVariableNames: 
    'elems '
  classVariableNames: ''
  poolDictionaries: ''    !


!Stack class methods !
   
new
    ^ self basicNew initialize! !



!Stack methods !
  
do: aBlock
    elems do: aBlock!
   
initialize
    elems := OrderedCollection new!
 
pop
   elems removeFirst!
  
printString
    ^ (self class) printString , '(' , self printStringElements , ' )'!

printStringElements
    | s |
    s := ''.
    elems do: [ :e | s := s , ' ' , e printString].
    ^s!
  
push: anElement
    elems addFirst: anElement!
 
size
    ^ elems size!
 
top
    ^ elems first! !
