Previous Page Next Page Contents

adt::Stack -- abstract data type ``Stack''

Introduction

adt::Stack implements the abstract data type ``Stack''.

Call(s)

adt::Stack(stack)

Parameters

stack - an expression sequence of objects to initialize the stack

Returns

an object of the domain adt::Stack

Details

Example 1

Create a new stack with strings as arguments.

>> S := adt::Stack("1", "2", "3", "4")
                                  Stack1

Show the length of the stack.

>> S::depth()
                                     4

Fill up the stack with a new element. The stack will be changed by the method, no new assignment to S is necessary!

>> S::push("5")
                                    "5"

Show the top of the stack. This method does not change the stack.

>> S::top(), S::top()
                                 "5", "5"

After twice getting an element of the stack, the third element is the new top of the stack, and the length is 3.

>> S::pop(), S::pop(), S::top(), S::depth()
                             "5", "4", "3", 3

Now revert the stack. The last element will be the first element.

>> S::reverse(): S::top()
                                    "1"

Fill up the stack with "0".

>> S::push("0"):
   S::empty()
                                   FALSE

Finally collect all elements of the stack in the list assigned to ARGS, until the stack is empty.

>> ARGS := []: while not S::empty() do ARGS := append(ARGS, S::pop()) end:
   ARGS
                           ["0", "1", "2", "3"]

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000