Skip to main content Accessibility help
×
Hostname: page-component-7bb8b95d7b-nptnm Total loading time: 0 Render date: 2024-09-28T13:16:27.031Z Has data issue: false hasContentIssue false

Program 6 - Playing Pools

Published online by Cambridge University Press:  05 July 2014

Get access

Summary

The purpose of this program is to illustrate the declaration of storage pools. It implements the well known Tower of Hanoi in which a tower of graduated discs is moved from one pole to another pole using a third pole as ‘temporary storage’ without any disc ever being on a smaller disc.

Each pole is represented by a stack and, in order to add variety, two kinds of stack are implemented much as in Exercise 14.9(3). One is a linked list and the other is an array. The choice of stack is made by the user and the program dispatches to the relevant subprograms Push and Pop as necessary.

The package Pools declares the type Pond and its associated operations Allocate, Deallocate, Initialize, Finalize, and Storage_Size. The package Heap then declares the one storage pool used in this example with the discriminant giving its size.

There is then a root package Stacks defining the limited interface Stack and abstract operations Push and Pop. The child packages Stacks.Linked and Stacks.Vector then declare the derived types L_Stack and V_Stack which implement the two kinds of stacks.

The package Tower declares the three poles and procedures Start and Move. The procedure Move implements the familiar recursive algorithm.

Two access types are involved, Stack_Ptr in the package Tower for the class wide pointers to the three stacks and Cell_Ptr in the package Stacks.Linked for the cells making up the linked stack. Both use the same storage pool, The_Pool, declared in the package Heap.

Type
Chapter
Information
Publisher: Cambridge University Press
Print publication year: 2014

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

Save book to Kindle

To save this book to your Kindle, first ensure coreplatform@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.

Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

  • Playing Pools
  • John Barnes
  • Book: Programming in Ada 2012
  • Online publication: 05 July 2014
  • Chapter DOI: https://doi.org/10.1017/CBO9781139696616.037
Available formats
×

Save book to Dropbox

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.

  • Playing Pools
  • John Barnes
  • Book: Programming in Ada 2012
  • Online publication: 05 July 2014
  • Chapter DOI: https://doi.org/10.1017/CBO9781139696616.037
Available formats
×

Save book to Google Drive

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.

  • Playing Pools
  • John Barnes
  • Book: Programming in Ada 2012
  • Online publication: 05 July 2014
  • Chapter DOI: https://doi.org/10.1017/CBO9781139696616.037
Available formats
×