eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'Stack':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: Stack


Inheritance:

   Object
   |
   +--Collection
      |
      +--SequenceableCollection
         |
         +--OrderedCollection
            |
            +--Stack

Package:
stx:libbasic2
Category:
Collections-Ordered
Version:
rev: 1.16 date: 2021/06/03 07:03:45
user: cg
file: Stack.st directory: libbasic2
module: stx stc-classLibrary: libbasic2

Description:


A simple implementation of a Stack.

Notice, this is simply syntactic sugar - all functionality is
already provided by the OrderedCollection class 
(addLast <==> push / removeLast <==> pop / last <==> top)

[complexity:]
    see OrderedCollection

copyright

COPYRIGHT (c) 1996 by Claus Gittinger All Rights Reserved This software is furnished under a license and may be used only in accordance with the terms of that license and with the inclusion of the above copyright notice. This software may not be provided or otherwise made available to, or used by, any other person. No title to or ownership of the software is hereby transferred.

Class protocol:

instance creation
o  new
(comment from inherited method)
create a new, empty OrderedCollection


Instance protocol:

accessing
o  drop: n
remove n elements from the top of the stack.

o  pop
Answer the object on top of the stack.

o  pop: numElem
Pop and discard top numElems and answer the receiver.
Caveat: pop: is a misleading name; should propably be called drop:

** This is an obsolete interface - do not use it (it may vanish in future versions) **

o  push: anObject
Push anObject onto the top of the stack.
Return the pushed object.

o  top
Answer (without removing) the object on top of the stack.

enumerating
o  do: aBlock
Evaluate aBlock for each object on the stack, from top to bottom.

o  reverseDo: aBlock
Evaluate aBlock for each object on the stack, from bottom to top.


Examples:


push-push-....
  |aStack|

  aStack := Stack new.
  Transcript showCR:aStack.
  Transcript showCR:'push 1: '.
  aStack push:1.
  Transcript showCR:'push 2: '.
  aStack push:2.
  Transcript showCR:'push 3: '.
  aStack push:3.
  Transcript showCR:aStack.
  Transcript show:'pop: '; showCR:(aStack pop).
  Transcript show:'pop: '; showCR:(aStack pop).
  Transcript show:'pop: '; showCR:(aStack pop).
  Transcript showCR:aStack.
popping too many:
  |aStack|

  aStack := Stack new.
  aStack push:1.

  aStack pop.
  aStack pop.


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sat, 21 Dec 2024 17:11:36 GMT