Search procedure in modula 2

Moderators: jkien, Xilvo

Reageer
Gebruikersavatar
Berichten: 7.390

Search procedure in modula 2

Code: Selecteer alles

	...

  CONST

SIZE = ...; (*Number of records in array *)

... 

  TYPE

KeyType = ...;

(* any type accepting relational operators *)

ArrayType  = ARRAY[0..Size] OF RecordType;

RecordType = RECORD

   Key : KeyType;

   ...

 END

...

  VAR

Data : ArrayType;

Key  : KeyType;

Found: [0..Size];

...

 BEGIN

...

Key := ...;

Found := Search(Data,Key);

IF Found = 0

  THEN WrStr(“Item not found”)

  ELSE (* Write contents of Data[Found] *)

...

END (* IF *);

  ...


Klopt het dat de Found een out-of-range detectie vervult in bovenstaande code?

Alvast bedankt!
"C++ : Where friends have access to your private members." Gavin Russell Baker.

Reageer