Gebruikersavatar
In physics I trust
Artikelen: 0
Berichten: 7.390
Lid geworden op: za 31 jan 2009, 08:09

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.

Terug naar “Informatica en programmeren”