-- Item : Simple Search Procedure -- Reference : Data Structures and Program Design, Pascal, p 244. -- Author : Kruse, recoded by Paul Stachour, stachour@winternet.com -- Version : 1.0, 1999/Jan/12 -- 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 procedure ch7_ss is -- demo procedure to drive example. -- types and constants for the driver. type key_type is new integer; -- For the demo, keys are integers subtype Position is Natural; -- Descrete for type-safety type list_entry is -- An entry in the list. record key: key_type; data: integer; end record; type list is array(Position range <>) of list_entry; ss_list: list := ( (key => 1, data => 3), (key => 2, data => 3), (key => 3, data => 7), (key => 101, data => 32767) ); Is_Found : BOOLEAN := False; Where : Position; procedure sequential_search (L: in list; -- The list to be searched Target: in Key_Type; -- The target of the search Found: out BOOLEAN; -- Was the search successful? Location: out Position) is -- Where in list if successful -- Pre : The contiguous list L has been created -- Post: In an entry in L has key equal to target, then Found becomes -- TRUE and Location contains the position of such entry. Otherwise -- Found becomes False and Location becomes invalid. begin Found := False; for Loc in L'Range loop -- We loop through range of possibilities if L(lOC).Key = Target then -- Did we find it? Found := TRUE; Location := Loc; exit; -- Yes, so indicate and exit end if; end loop; end Sequential_Search; begin Sequential_Search (L => ss_list, Target => 3, Found => Is_Found, Location => Where); Sequential_Search (L => ss_list, Target => 101, Found => Is_Found, Location => Where); Sequential_Search (L => ss_list, Target => 237, Found => Is_Found, Location => Where); end ch7_ss;