
Stack subclass: #CachedStack
  instanceVariableNames: 
    'cache '
  classVariableNames: ''
  poolDictionaries: ''   !


!CachedStack class methods ! !



!CachedStack methods !
 
pop
    (cache isNil)
        ifTrue: [super pop]
        ifFalse: [cache := nil]!
   
printStringElements
     | s |
     s := ''.
     (cache notNil)
        ifTrue: [ s := cache printString].
     s := s , super printStringElements.
     ^ s!

push:anElem
    (cache notNil)
        ifTrue: [super push: cache].
    cache := anElem!
 
size
   ^ super size +
        ( (cache isNil) ifTrue: [0 ]  ifFalse: [ 1])!
  
top
    (cache isNil)
        ifTrue: [^super top]
        ifFalse: [^cache]! !
