Skip to main content

The Heap and One-way Linked Lists

  • Chapter
Modula-2 Applied

Part of the book series: Macmillan Computer Science Series ((COMPSS))

  • 23 Accesses

Abstract

In the diagram package the user can create a diagram made up of a series of shapes, each of which contains a number of items. Each shape can consist of any number of items, and there can be any number of shapes. Thus, when the program is written, it is not known how many items are required, or how many shapes are needed. This can be determined only when the program is being run. However, space is needed in which these items and shapes are stored. It would be possible to predeclare this using VAR statements of the form:

$$\matrix{ {{\rm{VAR}}\,{\rm{Shapes}}\,{\rm{:}}\,{\rm{ARRAY}}\,{\rm{[0}}..{\rm{SapeMax]}}\,{\rm{OF}}\,{\rm{Itemes;}}} \cr {\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,{\rm{Items}}\,{\rm{:}}\,{\rm{ARRAY}}\,{\rm{[0}}..{\rm{ItemMax]}}\,{\rm{OF}}\,{\rm{GCommand;}}} \cr }$$

where ShapeMax and ItemMax are suitable constants, and GCommand is a record defining an item (see chapter 9). This is limiting, as the user is restricted as to the number of GCommands that can make up a shape, and the number of shapes. It is also wasteful of memory, as some shapes may require very few GCommands. A much better solution is one where the memory for a new GCommand is acquired as and when it is needed, that is, when the program is run. This is achieved using the heap (see Wirth[1]).

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. Nikiaus Wirth Algorithms and Data Structures Prentice-Hall 1986

    Google Scholar 

  2. Niklaus Wirth Programming in Modula-2 Fourth Edition 1988 Springer-Verlag

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Copyright information

© 1991 R. J. Mitchell

About this chapter

Cite this chapter

Mitchell, R.J. (1991). The Heap and One-way Linked Lists. In: Modula-2 Applied. Macmillan Computer Science Series. Palgrave, London. https://doi.org/10.1007/978-1-349-12439-8_12

Download citation

  • DOI: https://doi.org/10.1007/978-1-349-12439-8_12

  • Publisher Name: Palgrave, London

  • Print ISBN: 978-0-333-55453-1

  • Online ISBN: 978-1-349-12439-8

  • eBook Packages: EngineeringEngineering (R0)

Publish with us

Policies and ethics