home *** CD-ROM | disk | FTP | other *** search
- S t a c k
- =========
-
- Documentation for module Stack
-
- Author: Michael Frieß [mif]
- Kernerstr. 22a
- 7000 Stuttgart 1
-
- Copyright remarks
- -----------------
-
- (C) Copyright 1988 by Michael Frieß. All rights reserved.
- The whole package (see chapter package) is public domain.
- All (source, documentation and code) is freely redistributable,
- as long as my name and the copyright notices remain intact, and
- only for non-commercial use. That means you can give it away, but
- don´t sell it.
- Commercial use without my explicit, written permission is not
- allowed. Contact me to get it and, perhaps, to pay some fee.
-
- Improvements and new ideas are welcome, as long as the changes are
- good documented inline and in the documentation files. I´would like
- to know, if you make major changes and repost it.
-
-
- Contents
- --------
-
- Package
- Introduction
- New Data Type "Stack"
- Stack-Operators
- Example of Use
- Further generic types
- Referenced Literature
-
-
- Package
- -------
-
- The whole package "Stack" consist of following files:
-
- Stack.doc This documentation file
- Stack.dok German documentation
- Stack.def Definition module
- Stack.mod Implementation module
- Stack.sym Symbol file
- Stack.obj Compiled object code
- TestOfStack.mod Test module (source)
- TestOfStack Test module in executable form
-
-
- Introduction
- ------------
-
- Often you need basic data structures and operations on
- them, which are not implemented in Modula-II.
- But Modula-II supports development of generic data types.
- The best known example of generic data type is "File".
- You can import File and procedures operating on it from
- system module "FileSystem".
- The one thing, you have to know, is the abstract concept
- of files, not the realization.
- This module offers a generic type "Stack". So you have not
- to reinvent wheel, e.g. program your own stack by pointers,
- every time, you need one. You just have to know the
- abstract concept of stacks.
- You find more description about generic data types and
- other stuff in the document written for the module "List".
-
-
- New Data Type "Stack"
- --------------------
-
- The generic type "Stack" is a simple LIFO-list. LIFO means
- last-in-first-out, so the last element put into the stack
- is the first get out.
-
-
- Stack-Operators
- ---------------
-
- In following operators and their abstract intention are listed.
- You can find more details in definition module.
-
- o Init
- initializes a new empty stack for further use.
-
- o Discard
- discards a stack and frees memory allocation.
-
- o Write
- puts a new element at the top of the stack.
-
- o Read
- gets top element of stack and removes it from stack.
-
- o Empty
- determines, whether a stack is empty or not.
-
-
- Example of Use
- --------------
- Using the type stack is very simple:
-
- 1) Import stack and needed operators:
-
- FROM Stack IMPORT stack, Init, Read, Write, Empty, Discard;
-
- 2) Define your element type:
- (for example:)
-
- TYPE name = ARRAY [1..30] OF CHAR;
-
- 3) Define a stack variable and a variable containing your data:
-
- VAR s : stack;
- Name : name;
-
- 4) Initialize stack s:
-
- Init (s);
-
- (or with qualified export/import:)
-
- Stack.Init (s);
-
- 5) Put first person into stack:
-
- Name := "Kant";
- Write (s, Name);
-
- inserting further person for example by reading from file or user
- input
-
- 6) Get toppest person in stack (probably not Mr. Kant, because he
- is at the bottom of the stack!):
-
- Read (s, Name);
-
- 7) Get all persons of stack:
-
- WHILE NOT Empty(s) DO
- Read(s, Name);
- - Display Name -
- END;
-
- 8) Discard the stack after use:
-
- Discard (s);
-
-
- Easy, isn´t it?
-
-
- Further generic types
- ---------------------
-
- I have implemented other generic data types:
-
- o queue
- a simple FIFO-list
-
- o list
- a more powerful linear list
-
- o AVL-Tree
- See [1] for detailed description
-
- Surely there are a lot of other possible generic types:
-
- o pipe
- There is a pipe-handler at a fish-disk (I don´t know the number).
- I would enjoy an implementation of a pipe-handler with whole
- Modula-II support as a generic type.
- The great advantage of a pipe is the simultaneous use by multiple
- processes. For example two processes write data into the pipe and
- one process reads data simultaneous.
- (I´m looking forward the module for fully support of amiga´s multi-
- tasking operating system!)
-
- o BTree
- Another sort of tree also described in [1].
-
- o Hash-Table
- Perhaps a hash-table is also a candidat for generic data type -
- I haven´t thought about it yet.
-
- I´m looking forward a lot of other implementations of generic data
- types. For free distribution on AMOK-Disks send your implementations
- to my address or just to any address of an AMOK-member.
-
- Referenced literature
- ---------------------
-
- [1] N.Wirth "Algorithmen und Datenstrukturen mit Modula-II"
- Teubner, Stuttgart 1986
-