| Data Structures and Algorithms |
| 3 Data Structures |
In this section, we will examine some fundamental data structures:
arrays, lists, stacks and trees.
Points to note:
A question:
Points to note:
No software without a consistent strategy for detecting, reporting and
recovering from errors can be considered well engineered. It is difficult to
debug, prone to crashes from faults which are difficult to correct because
there is no indication of the source of the error.
Error handling is addressed in a
later section.
3.1 Arrays
The simplest way to implement our collection is to use an array to hold the
items.
Thus the implementation of the collection object becomes:
/* Array implementation of a collection */
#include <assert.h> /* Needed for assertions */
#include "collection.h" /* import the specification */
struct t_collection {
int item_cnt;
int max_cnt; /* Not strictly necessary */
int item_size; /* Needed by FindInCollection */
void *items[];
};
Hint: it's related to the pre- and post-conditions specified
for methods on this object.
Key terms |
|
Continue on to Lists Back to the Table of Contents |