xvi Preface
As with any programming language, Java has both advantages and disadvan-
tages. Java is a small language. There usually is only one language feature to do
something, and this has the happy tendency of encouraging a programmer toward
clarity when used correctly. In this respect, it is superior to C or C
++
. Java serves
nicely for defining and using most traditional data structures such as lists and trees.
On the other hand, Java is quite poor when used to do file processing, being both
cumbersome and inefficient. It is also a poor language when fine control of memory
is required. As an example, applications requiring memory management, such as
those discussed in Section 12.3, are difficult to write in Java. Since I wish to stick
to a single language throughout the text, like any programmer I must take the bad
along with the good. The most important issue is to get the ideas across, whether
or not those ideas are natural to a particular language of discourse. Most program-
mers will use a variety of programming languages throughout their career, and the
concepts described in this book should prove useful in a variety of circumstances.
Inheritance, a key feature of object-oriented programming, is used sparingly
in the code examples. Inheritance is an important tool that helps programmers
avoid duplication, and thus minimize bugs. From a pedagogical standpoint, how-
ever, inheritance often makes code examples harder to understand since it tends to
spread the description for one logical unit among several classes. Thus, my class
definitions only use inheritance where inheritance is explicitly relevant to the point
illustrated (e.g., Section 5.3.1). This does not mean that a programmer should do
likewise. Avoiding code duplication and minimizing errors are important goals.
Treat the programming examples as illustrations of data structure principles, but do
not copy them directly into your own programs.
One painful decision I had to make was whether to use generics in the code
examples. Generics were not used in the first edition of this book. But in the years
since then, Java has matured and its use in computer science curricula has greatly
expanded. I now assume that readers of the text will be familiar with generic syntax.
Thus, generics are now used extensively in the code examples.
My implementations are meant to provide concrete illustrations of data struc-
ture principles, as an aid to the textual exposition. Code examples should not be
read or used in isolation from the associated text because the bulk of each exam-
ple’s documentation is contained in the text, not the code. The code complements
the text, not the other way around. They are not meant to be a series of commercial-
quality class implementations. If you are looking for a complete implementation
of a standard data structure for use in your own code, you would do well to do an
Internet search.
For instance, the code examples provide less parameter checking than is sound
programming practice, since including such checking would obscure rather than
illuminate the text. Some parameter checking and testing for other constraints
(e.g., whether a value is being removed from an empty container) is included in