< previous page page_790 next page >

Page 790
program. A data structure can be used to solve a problem, and yet not accurately reflect the relationships within the problem. If the data structure does not reflect these relationships, it is not an effective structure for that program.
A data structure is a framework for holding data. This framework should be tailored to each particular problem by reflecting the relationships among data values, making it easy for readers to see how the data items are related and how they should be processed to produce the required output. Because each problem is different, it is impossible to give a set of rules by which to judge an effective data structure. Instead, we examine the choices within a specific context, discuss the issues involved, and make some generalizations.
The Absentee program in Chapter 13 analyzed absentee data, made up of the number of people who were absent from each of six departments of a company during a particular week. The data were broken down further by day of the week. The main data structure used was a two-dimensional array absenteeData, where the first dimension represented departments and the second dimension represented the days of the week. Each component was an integer value that represented the number of people who were absent. A parallel, one-dimensional array average held the average daily absentee figures for each department (see Figure 14-6).
Would a record structure be a better choice to represent this information? Let's look at two possible representations of this same information as an array of structs, and discuss the implications of each representation.
const int NUM_DEPTS = 6;

enum DeptType {A, B, C, D, E, F};
enum DayType {MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY};
0790-01.gif
Figure 14-6
Arrays 
absenteeData and average

 
< previous page page_790 next page >