Page 78 - DCAP201_FUNDAMENTALS_OF_DATA_STRUCTURES
P. 78
Unit 5: Pointers
5.3.2 Representation of Records in Memory; Parallel Arrays Notes
If the records may contain non-homogeneous data, then the elements of a record cannot be
stored in an array. Some programming languages, such as PL/1, Pascal and COBOL, do have
record structures built into the language.
Example:
Consider the record structure Newborn in example of newborn. One can store such a record in
PL/1 following declaration, which defines a data aggregate called a structure:
DECLARE 1 NEWBORN,
2 NAME CHAR(20),
2 SEX CHAR(1),
2 BIRTHDAY,
3 MONTH FIXED,
3 DAY FIXED,
3 YEA R FIXED,
2 FATHER,
3 NAME CHAR(20),
3 AGE FIXED,
2 MOTHER
3 NAME CHAR(20),
3 AGE FIXED;
Let we observe that the variables SEX and YEAR are unique; hence references to them need not
be qualified. On the other hand, AGE is not unique. Accordingly, we should use like that
FATHER.AGE or MOTHER.AGE
when we want to reference the father’s age or the mother’s age.
If a programming language does not have available the hierarchical structures that are label in
PL/1, Pascal and COBOL. Assuming the record contains non-homogeneous data, the record may
have to be stored in individual variables, one for each of its elementary data items.
On the other hand, if we want to store an entire file of records, note that all data elements
belonging to the same identifier do have the same type. Such a file may be stored in memory as
a collection of parallel arrays; that is, where elements in the different arrays with the same
subscript belong to the same record. To understand this parallel arrays, let we go through the
following example.
Example:
Consider a membership list contains the name, age, sex and telephone number of each member.
We can store the file in four parallel arrays, NAME, AGE, SEX and PHONE, as pictured in Figure
5.6 ; that is, for a given subscript K, the elements NAME[K], AGE[K], SEX[K] and PHONE[K]
belong to the same record.
LOVELY PROFESSIONAL UNIVERSITY 71