-- Item : Contingous List Package Specification -- Reference : Data Structures and Program Design, Pascal, p 198 -- Author : Kruse, recoded by Paul Stachour, stachour@winternet.com -- Version : 1.0, 1999/Jan/21 -- For : ICS340, Winter 199, Metro State, Minnesota -- Style : Ada95, in a pascalish style, to match the textbook. -- Protection: Original copyright 1994, Prentice Hall -- Derivation: Derivation by permission; see Author for details -- Disclaimer: This routine has not been tested, only translated package ch6_cl is -- This file completes the declaration of a contiguous list package with the -- part common to all types of list entries. -- It requires that type listentry and maxlist be redeclared in this -- specification, and it be "with'ed" as appropriate. -- This style is taken to be similar to other languages, -- in Ada one would usually use an instantiated generic or a variant record. maxlist: constant integer := 10_000; type listentry is new integer; -- Should be Natural, Integer for compat. subtype position is integer range 1..maxlist; subtype listcount is integer range 0..maxlist; type cldata is array(position) of listentry; type list is record data: cldata; count: listcount; end record; type processlistentry is access procedure(LE: in out listentry); procedure CreateList(L: in out list); -- Pre: None. -- Post: The list L has been created and is initialized to be empty. procedure ClearList(L: in out list); -- Pre: The list L has been created. -- Post: All entries of the list L have been deleted. function ListEmpty(L: in list) return Boolean; -- Pre: The list L has been created. -- Post: The function returns true if the list L is empty, false otherwise. function ListFull(L: list) return Boolean; -- Pre: The list L has been created. -- Post: The function returns true if the list is full, false otherwise. function ListSize(L: list) return listcount; -- Pre: The list L has been created. -- Post: The function returns the number of entries in list L. procedure InsertList(p: position; x: listentry; L: in out list); -- Pre: The list L has been created, L is not full, x is a valid list -- entry, and 1 <= p <= n + 1, where n is the number of entries in -- L. -- Post: x has been inserted into position p in L; the entry formerly in -- position p (provided p <= n) and all later entries have their -- position numbers increased by 1. procedure DeleteList(p: position; x: out listentry; L: in out list); -- Pre: The list L has been created, L is not empty, -- and 1 <= p <= n, where n is the number of entries in L. -- Post: The entry in position p of L has been returned as x and deleted -- from L; the entries in all later positions (provided -- p < n) have their position numbers decreased by 1. procedure RetrieveList(p: position; x: out listentry; L: in out list); -- Pre: The list L has been created, L is not empty, -- and 1 <= p <= n, where n is the number of entries in L. -- Post: The entry in position p of L has been returned as x. L remains -- unchanged. procedure ReplaceList(p: position; x: listentry; L: in out list); -- Pre: The list L has been created, L is not empty, x is a valid list -- entry, and 1 <= p <= n, where n is the number of entries in L. -- Post: The entry in position p of L has been replaced by x. The other -- entries of L remain unchanged. procedure TraverseList(L: in out list; Visit: processlistentry); -- Pre: The list L has been created. -- Post: The action specified by the procedure Visit has been -- performed on every entry of the list L, beginning at the first -- entry and doing each in turn. -- Uses: RetrieveList, ReplaceList. end ch6_cl;