SlideShare a Scribd company logo
Explore the full ebook collection and download it now at textbookfull.com
Object Oriented Data Structures Using Java 4th
Edition Dale
https://textbookfull.com/product/object-oriented-data-
structures-using-java-4th-edition-dale/
OR CLICK HERE
DOWLOAD EBOOK
Browse and Get More Ebook Downloads Instantly at https://textbookfull.com
Click here to visit textbookfull.com and download textbook now
Your digital treasures (PDF, ePub, MOBI) await
Download instantly and pick your perfect format...
Read anywhere, anytime, on any device!
Object Orientation Abstraction and Data Structures Using
Scala Second Edition Lacher
https://textbookfull.com/product/object-orientation-abstraction-and-
data-structures-using-scala-second-edition-lacher/
textbookfull.com
A Functional Approach to Java: Augmenting Object-Oriented
Java Code with Functional Principles 1st Edition Ben
Weidig
https://textbookfull.com/product/a-functional-approach-to-java-
augmenting-object-oriented-java-code-with-functional-principles-1st-
edition-ben-weidig/
textbookfull.com
Practical object-oriented design: an agile primer using
Ruby Second Edition Metz
https://textbookfull.com/product/practical-object-oriented-design-an-
agile-primer-using-ruby-second-edition-metz/
textbookfull.com
Swift 3 Object Oriented Programming Gaston C. Hillar
https://textbookfull.com/product/swift-3-object-oriented-programming-
gaston-c-hillar/
textbookfull.com
Introduction to Java Programming and Data Structures
Comprehensive Version Y Daniel Liang
https://textbookfull.com/product/introduction-to-java-programming-and-
data-structures-comprehensive-version-y-daniel-liang/
textbookfull.com
Problem Solving in Data Structures & Algorithms Using C
First Edition Jain
https://textbookfull.com/product/problem-solving-in-data-structures-
algorithms-using-c-first-edition-jain/
textbookfull.com
Programming In C Object Oriented Features 1st Edition
Laxmisha Rai
https://textbookfull.com/product/programming-in-c-object-oriented-
features-1st-edition-laxmisha-rai/
textbookfull.com
Advanced Object-Oriented Programming in R: Statistical
Programming for Data Science, Analysis and Finance 1st
Edition Thomas Mailund
https://textbookfull.com/product/advanced-object-oriented-programming-
in-r-statistical-programming-for-data-science-analysis-and-
finance-1st-edition-thomas-mailund/
textbookfull.com
Think Data Structures: Algorithms and Information
Retrieval in Java 1st Edition Allen B. Downey
https://textbookfull.com/product/think-data-structures-algorithms-and-
information-retrieval-in-java-1st-edition-allen-b-downey/
textbookfull.com
Object Oriented Data Structures Using Java 4th Edition Dale
Object Oriented Data Structures Using Java 4th Edition Dale
Java™
Fourth Edition
Nell Dale
University of Texas, Austin
Daniel T. Joyce
Villanova University
Chip Weems
University of Massachusetts,
Amherst
Java
using
Object-Oriented
Data Structures
World Headquarters
Jones & Bartlett Learning
5 Wall Street
Burlington, MA 01803
978-443-5000
info@jblearning.com
www.jblearning.com
Jones & Bartlett Learning books and products are available through most bookstores and online booksellers. To contact Jones & Bartlett
Learning directly, call 800-832-0034, fax 978-443-8000, or visit our website, www.jblearning.com.
Substantial discounts on bulk quantities of Jones & Bartlett Learning publications are available to corporations, professional associa-
tions, and other qualified organizations. For details and specific discount information, contact the special sales department at Jones &
Bartlett Learning via the above contact information or send an email to specialsales@jblearning.com.
Copyright © 2018 by Jones & Bartlett Learning, LLC, an Ascend Learning Company
All rights reserved. No part of the material protected by this copyright may be reproduced or utilized in any form, electronic or mechani-
cal, including photocopying, recording, or by any information storage and retrieval system, without written permission from the copyright
owner.
The content, statements, views, and opinions herein are the sole expression of the respective authors and not that of Jones & Bartlett Learn-
ing, LLC. Reference herein to any specific commercial product, process, or service by trade name, trademark, manufacturer, or otherwise
does not constitute or imply its endorsement or recommendation by Jones & Bartlett Learning, LLC and such reference shall not be used for
advertising or product endorsement purposes. All trademarks displayed are the trademarks of the parties noted herein. Object-Oriented Data
Structures Using Java, Fourth Edition is an independent publication and has not been authorized, sponsored, or otherwise approved by the
owners of the trademarks or service marks referenced in this product.
09820-4
Production Credits
VP, Executive Publisher: David D. Cella
Acquisitions Editor: Laura Pagluica
Editorial Assistant: Taylor Ferracane
Director of Vendor Management: Amy Rose
Marketing Manager: Amy Langlais
VP, Manufacturing and Inventory Control: Therese Connell
Composition and Project Management: S4Carlisle Publishing Services
Cover Design: Kristin E. Parker
Text Design: Scott Moden
Rights & Media Specialist: Merideth Tumasz
Media Development Editor: Shannon Sheehan
Cover Image: © Ake13bk/Shutterstock
Printing and Binding: Edwards Brothers Malloy
Cover Printing: Edwards Brothers Malloy
Library of Congress Cataloging-in-Publication Data
Names: Dale, Nell (Nell B.), author. | Joyce, Daniel T., author. | Weems,
Chip., author.
Title: Object-oriented data structures using Java / Nell Dale, Daniel T.
Joyce, Chip Weems.
Description: Fourth edition. | Burlington, MA : Jones & Bartlett Learning,
[2017]
Identifiers: LCCN 2016025145 | ISBN 9781284089097 (casebound)
Subjects: LCSH: Object-oriented programming (Computer science) | Data
structures (Computer science) | Java (Computer program language)
Classification: LCC QA76.64 .D35 2017 | DDC 005.13/3--dc23 LC record available at
https://lccn.loc.gov/2016025145
6048
Printed in the United States of America
20 19 18 17 16 10 9 8 7 6 5 4 3 2 1
To Alfred G. Dale
ND
To Kathy, Tom, and Julie, thanks for the love and support
DJ
To Lisa, Charlie, and Abby, thank you . . .
CW
©
Ake13bk/Shutterstock
Welcome to the fourth edition of Object-Oriented Data Structures Using Java™. This book pres-
ents the algorithmic, programming, and structuring techniques of a traditional data structures
course in an object-oriented context. You’ll find the familiar topics of linked lists, recursion,
stacks, queues, collections, indexed lists, trees, maps, priority queues, graphs, sorting, searching,
and complexity analysis, all covered from an object-oriented point of view using Java. We stress
software engineering principles throughout, including modularization, information hiding, data
abstraction, stepwise refinement, the use of visual aids, the analysis of algorithms, and software
verification methods.
To the Student
You know that an algorithm is a sequence of unambiguous instructions for solving a problem.
You can take a problem of moderate complexity, design a small set of classes/objects that work
together to solve the problem, code the method algorithms needed to make the objects work, and
demonstrate the correctness of your solution.
Algorithms describe actions. These actions manipulate data. For most interesting problems
that are solved using computers, the structure of the data is just as important as the structure
of the algorithms used to manipulate the data. Using this text you will discover that the way
you structure data affects how efficiently you can use the data; you will see how the nature of
the problem you are attempting to solve dictates your structuring decisions; and you will learn
about the data structures that computer scientists have developed over the years to help solve
problems.
Object-Oriented Programming with Java
Our primary goal is to present both the traditional and modern data structure topics with an
emphasis on problem solving and software design. Using the Java programming language as a
vehicle for problem solutions, however, presents an opportunity for students to expand their
Preface
Preface v
familiarity with a modern programming language and the object-oriented paradigm. As our data
structure coverage unfolds, we introduce and use the appropriate Java constructs that support our
primary goal. Starting early and continuing throughout the text, we introduce and expand on the
use of many Java features such as classes, objects, generics, polymorphism, packages, interfaces,
library classes, inheritance, exceptions, and threads. We also use Universal Modeling Language
(UML) class diagrams throughout to help model and visualize our objects, classes, interfaces,
applications, and their interrelationships.
Features
Data Abstraction In this text we view our data structures from three different perspectives:
their specification, their application, and their implementation. The specification describes the
logical or abstract level—what the logical relationships among the data elements are and what
operations can be performed on the structure. The application level, sometimes called the client
level, is concerned with how the data structure is used to solve a problem—why the operations
do what they do. The implementation level involves the coding details—how the structures
and operations are implemented. In other words we treat our data structures as abstract data
types (ADTs).
Efficiency Analysis In Chapter 1 we introduce order of growth efficiency analysis using a unique
approach involving the interaction of two students playing a game. Time and space analysis is
consistently applied throughout the text, allowing us to compare and contrast data structure
implementations and the applications that use them.
Recursion Treatment Recursion is introduced early (Chapter 3) and used throughout the re-
mainder of the text. We present a design and analysis approach to recursion based on answering
three simple questions. Answering the questions, which are based on formal inductive reasoning,
leads the programmer to a solid recursive design and program.
Interesting Applications Eight primary data structures (stacks, queues, collections, indexed
lists, trees, maps, priority queues, and graphs) are treated in separate chapters that include their
definition, several implementations, and one or more interesting applications based on their use.
Applications involve, for example, balanced expressions, postfix expressions, image generation
(new!), fractals (new!), queue simulation, card decks and games (new!), text analysis (new!), tree
and graph traversals, and big integers.
Robust Exercises We average more than 40 exercises per chapter. The exercises are organized by
chapter sections to make them easier for you to manage. They vary in level of difficulty, including
short and long programming problems (marked with “programming-required” icons—one icon
to indicate short exercises and two icons for projects), the analysis of algorithms, and problems
to test students’ understanding of abstract concepts. In this edition we have streamlined the
previous exercises, allowing us to add even more options for you to choose from. In particular
we have added several larger programming exercises to many of the chapters.
Input/Output Options It is difficult to know what background the students using a data struc-
tures text will have in Java I/O. To allow all the students using our text to concentrate on the
vi Preface
primary topic of data structures, we use the simplest I/O approach we can, namely a command
line interface. However, to support those teachers and students who prefer to work with graphi-
cal user interfaces (GUIs), we provide GUIs for many of our applications. Our modular approach
to program design supports this approach—our applications separate the user interface code,
problem solution code, and ADT implementation code into separate classes.
Concurrency Coverage We are pleased to be one of the only data structures texts to address the
topics of concurrency and synchronization, which are growing in importance as computer systems
move to using more cores and threads to obtain additional performance with each new generation.
We introduce this topic in Section 4.9, “Concurrency, Interference, and Synchronization,” where
we start with the basics of Java threads, continue through examples of thread interference and
synchronization, and culminate in a discussion of efficiency concerns.
New to the Fourth Edition
This edition represents a major revision of the text’s material, although the philosophy and style
that our loyal adopters have grown to appreciate remain unchanged. We removed material we
felt was redundant or of lesser/outdated importance to the core topic of data structures, added
new key material, and reworked much of the material that we kept. Although the length of the
textbook was reduced by about 10%, the coverage of data structures has been expanded. We
believe this new edition is a great improvement over previous editions and hope you do, too.
Major changes include:
• Simplified Architecture: We continue to use the Java interface construct to
define the abstract view of our ADTs, but we have reduced the number of levels
of inheritance, simplifying the architecture and making it easier to understand
and use.
• New Chapters: Chapter 5, “The Collection ADT,” and Chapter 8, “The Map ADT,” are
brand new. The Collection ADT material introduces the idea of a data structure as
a repository and concentrates on storage and retrieval of data based on key attri-
butes. The Map ADT has become increasingly important with the rise in popularity
of scripting languages with built-in associative arrays.
• New Section: Section 1.6, “Comparing Algorithms: Order of Growth Analysis,” was
completely rewritten and features an introduction to efficiency analysis driven by
a game played between two students, plus analysis of sequential search, binary
search, and sequential sort algorithms.
• New Sections: In response to reader’s suggestions, Chapter 3, “Recursion,” features
two new sections: Section 3.3, “Recursive Processing of Arrays,” is devoted to recur-
sive processing of arrays and Section 3.4, “Recursive Processing of Linked Lists,” is
devoted to recursive processing of linked lists. These new sections provide practical
examples of the use of recursion, before the reader moves on to the less practical
but nevertheless popular Towers of Hanoi example covered in Section 3.5, “Towers.”
• New Section: Fractals! A fun section related to recursively generating fractal-based
images now wraps up the examples of Chapter 3, “Recursion.”
Preface vii
• New Sections: We added “Variations” sections to the Stack, Queue, Collection, List,
Tree, and Map chapters. In the primary exposition of each of these ADTs we record
design decisions and specify the operations to be supported by the ADT. We also
develop or at least discuss various implementation approaches, in most cases high-
lighting one array-based approach and one reference/linked-list-based approach.
The “Variations” section discusses alternate approaches to defining/implementing
the ADT and in most cases reviews the ADT counterparts available in the standard
Java Library. Some of these sections also introduce related ADTs, for example, in the
“Variations” section of the Collection chapter we define and discuss both the Set
and Bag ADTs.
• Glossary: The text’s glossary has always been available online. With this edition we
make it available as Appendix E. Throughout the text we highlight important terms
that might be unfamiliar to the student in green, the first time they are featured, to
indicate that their definition can be found in the glossary.
Prerequisite Assumptions
In this book, we assume that readers are familiar with the following Java constructs:
• Built-in simple data types and the array type
• Control structures while, do, for, if, and switch
• Creating and instantiating objects
• Basic user-defined classes:
■ variables and methods
■ constructors, method parameters, and the return statement
■ visibility modifiers
• Commonly used Java Library Classes: Integer, Math, Random, Scanner, String,
and System
Chapter Content
Chapter 1 is all about Getting Organized. An overview of object orientation stresses mecha-
nisms for organizing objects and classes. The Java exception handling mechanisms, used to
organize response to unusual situations, are introduced. Data structures are previewed and the
two fundamental language constructs that are used to implement those structures, the array
and the reference (link/pointer), are discussed. The chapter concludes with a look at efficiency
analysis—how we evaluate and compare algorithms.
Chapter 2 presents The Stack ADT. The concept of abstract data type (ADT) is introduced.
The stack is viewed from three different levels: the abstract, application, and implementation
levels. The Java interface mechanism is used to support this three-tiered view. We also investigate
using generics to support generally usable ADTs. The Stack ADT is implemented using both arrays
and references. To support the reference-based approach we introduce the linked list structure.
Sample applications include determining if a set of grouping symbols is well formed and the
evaluation of postfix expressions.
viii Preface
Chapter 3 discusses Recursion, showing how recursion can be used to solve programming
problems. A simple three-question technique is introduced for verifying the correctness of re-
cursive methods. Sample applications include array processing, linked list processing, the classic
Towers of Hanoi, and fractal generation. A detailed discussion of how recursion works shows how
recursion can be replaced with iteration and stacks.
Chapter 4 presents The Queue ADT. It is also first considered from its abstract perspective,
followed by a formal specification, and then implemented using both array-based and reference-
based approaches. Example applications include an interactive test driver, a palindrome checker,
and simulating a system of real-world queues. Finally, we look at Java’s concurrency and synchro-
nization mechanisms, explaining issues of interference and efficiency.
Chapter 5 defines The Collection ADT. A fundamental ADT, the Collection, supports storing
information and then retrieving it later based on its content. Approaches for comparing objects
for equality and order are reviewed. Collection implementations using an array, a sorted array,
and a linked list are developed. A text processing application permits comparison of the imple-
mentation approaches for efficiency. The “Variations” section introduces two more well-known
ADTs: the Bag and the Set.
Chapter 6 follows up with a more specific Collection ADT, The List ADT. In fact, the following
two chapters also develop Collection ADTs. Iteration is introduced here and the use of anonymous
inner classes to provide iterators is presented. As with the Collection ADT we develop array, sorted
array, and linked-list–based implementations. The “Variations” section includes an example of
how to “implement” a linked list within an array. Applications include a card deck model plus
some card games, and a Big Integer class. This latter application demonstrates how we sometimes
design specialized ADTs for specific problems.
Chapter 7 develops The Binary Search Tree ADT. It requires most of the chapter just to
design and create our reference-based implementation of this relatively complex structure. The
chapter also discusses trees in general (including breadth-first and depth-first searching) and the
problem of balancing a binary search tree. A wide variety of special-purpose and self-balancing
trees are introduced in the “Variations” section.
Chapter 8 presents The Map ADT, also known as a symbol table, dictionary, or associative
array. Two implementations are developed, one that uses an ArrayList and the other that uses a
hash table. A large part of the chapter is devoted to this latter implementation and the important
concept of hashing, which provides a very efficient implementation of a Map. The “Variations”
section discusses a map-based hybrid data structure plus Java’s support for hashing.
Chapter 9 introduces The Priority Queue ADT, which is closely related to the Queue but with
a different accessing protocol. This short chapter does present a sorted array-based implementa-
tion, but most of the chapter focuses on a clever, interesting, and very efficient implementation
called a Heap.
Chapter 10 covers The Graph ADT, including implementation approaches and several
important graph-related algorithms (depth-first search, breadth-first search, path existence,
shortest paths, and connected components). The graph algorithms make use of stacks, queues,
and priority queues, thus both reinforcing earlier material and demonstrating the general us-
ability of these structures.
Preface ix
Chapter 11 presents/reviews a number of Sorting and Searching Algorithms. The sorting
algorithms that are illustrated, implemented, and compared include straight selection sort, two
versions of bubble sort, insertion sort, quick sort, heap sort, and merge sort. The sorting algo-
rithms are compared using efficiency analysis. The discussion of algorithm analysis continues in
the context of searching. Previously presented searching algorithms are reviewed and new ones
are described.
Organization
Chapter Goals Sets of knowledge and skill goals are presented at the beginning of each chapter
to help the students assess what they have learned.
Sample Programs Numerous sample programs and program segments illustrate the abstract
concepts throughout the text.
Feature Sections Throughout the text these short sections highlight topics that are not directly
part of the flow of material but nevertheless are related and important.
Boxed Notes These small boxes of information scattered throughout the text highlight, supple-
ment, and reinforce the text material, perhaps from a slightly different point of view.
Chapter Summaries Each chapter concludes with a summary section that reviews the most im-
portant topics of the chapter and ties together related topics. Some chapter summaries include a
UML diagram of the major interfaces and classes developed within the chapter.
Appendices The appendices summarize the Java reserved word set, operator precedence, primitive
data types, the ASCII subset of Unicode, and provide a glossary of important terms used in the text.
Website http://go.jblearning.com/oods4e
This website provides access to the text’s source code files for each chapter. Additionally, regis-
tered instructors are able to access selected answers to the text’s exercises, a test item file, and
presentation slides. Please contact the authors if you have material related to the text that you
would like to share with others.
x Preface
Acknowledgments
We would like to thank the following people who took the time to review this text: Mark
Llewellyn at the University of Central Florida, Chenglie Hu at Carroll College, Val Tannen
at the University of Pennsylvania, Chris Dovolis at the University of Minnesota, Mike Coe at
Plano Senior High School, Mikel Petty at University of Alabama in Huntsville, Gene Sheppard
at Georgia Perimeter College, Noni Bohonak at the University of South Carolina–Lancaster,
Jose Cordova at the University of Louisiana–Monroe, Judy Gurka at the Metropolitan State
College of Denver, Mikhail Brikman at Salem State University, Amitava Karmaker at University
of Wisconsin–Stout, Guifeng Shao at Tennessee State University, Urska Cvek at Louisiana State
University at Shreveport, Philip C. Doughty Jr. at Northern Virginia Community College, Jeff
Kimball at Southwest Baptist University, Jeremy T. Lanman at Nova Southeastern University,
Rao Li at University of South Carolina Aiken, Larry Thomas at University of Toledo, and Karen
Works at Westfield State University. A special thanks to Christine Shannon at Centre College, to
Phil LaMastra at Fairfield University, to Allan Gottlieb of New York University, and to J. William
Cupp at Indiana Wesleyan University for specific comments leading to improvements in the
text. A personal thanks to Kristen Obermyer, Tara Srihara, Sean Wilson, Christopher Lezny, and
Naga Lakshmi, all of Villanova University, plus Kathy, Tom, and Julie Joyce for all of their help,
support, and proofreading expertise.
A virtual bouquet of roses to the editorial and production teams who contributed so much,
especially Laura Pagluica, Taylor Ferracane, Amy Rose, and Palaniappan Meyyappan.
ND
DJ
CW
©
Ake13bk/Shutterstock
1 Getting Organized 1
1.1 Classes, Objects, and Applications 2
Classes 2
The Unified Method 7
Objects 8
Applications 10
1.2 Organizing Classes 12
Inheritance 12
Packages 19
1.3 Exceptional Situations 22
Handling Exceptional Situations 22
Exceptions and Classes: An Example 23
1.4 Data Structures 27
Implementation-Dependent Structures 28
Implementation-Independent Structures 29
What Is a Data Structure? 31
1.5 Basic Structuring Mechanisms 32
Memory 32
References 34
Arrays 38
1.6 Comparing Algorithms: Order of Growth Analysis 43
Measuring an Algorithm’s Time Efficiency 44
Complexity Cases 45
Size of Input 46
Comparing Algorithms 47
Order of Growth 49
Contents
xii Contents
Selection Sort 50
Common Orders of Growth 53
Summary 54
Exercises 55
2 The Stack ADT 67
2.1 Abstraction 68
Information Hiding 68
Data Abstraction 69
Data Levels 70
Preconditions and Postconditions 71
Java Interfaces 72
Interface-Based Polymorphism 76
2.2 The Stack 78
Operations on Stacks 79
Using Stacks 79
2.3 Collection Elements 81
Generally Usable Collections 81
2.4 The Stack Interface 84
Exceptional Situations 85
The Interface 88
Example Use 89
2.5 Array-Based Stack Implementations 90
The ArrayBoundedStack Class 91
Definitions of Stack Operations 93
The ArrayListStack Class 99
2.6 Application: Balanced Expressions 101
The Balanced Class 102
The Application 107
The Software Architecture 111
2.7 Introduction to Linked Lists 111
Arrays Versus Linked Lists 111
The LLNode Class 113
Operations on Linked Lists 115
2.8 A Link-Based Stack 121
The LinkedStack Class 122
The push Operation 124
The pop Operation 127
The Other Stack Operations 129
Comparing Stack Implementations 131
2.9 Application: Postfix Expression Evaluator 132
Discussion 132
Evaluating Postfix Expressions 133
Contents xiii
Postfix Expression Evaluation Algorithm 134
Error Processing 136
The PostFixEvaluator Class 137
The PFixCLI Class 139
2.10 Stack Variations 142
Revisiting Our Stack ADT 142
The Java Stack Class and the Collections Framework 143
Summary 145
Exercises 147
3 Recursion 161
3.1 Recursive Definitions, Algorithms, and Programs 162
Recursive Definitions 162
Recursive Algorithms 163
Recursive Programs 166
Iterative Solution for Factorial 167
3.2 The Three Questions 167
Verifying Recursive Algorithms 168
Determining Input Constraints 169
Writing Recursive Methods 169
Debugging Recursive Methods 170
3.3 Recursive Processing of Arrays 170
Binary Search 170
3.4 Recursive Processing of Linked Lists 174
Recursive Nature of Linked Lists 175
Traversing a Linked List 175
Transforming a Linked List 178
3.5 Towers 182
The Algorithm 182
The Method 184
The Program 186
3.6 Fractals 186
A T-Square Fractal 187
Variations 190
3.7 Removing Recursion 191
How Recursion Works 191
Tail Call Elimination 195
Direct Use of a Stack 196
3.8 When to Use a Recursive Solution 197
Recursion Overhead 198
Inefficient Algorithms 198
Clarity 200
xiv Contents
Summary 202
Exercises 202
4 The Queue ADT 217
4.1 The Queue 218
Operations on Queues 219
Using Queues 219
4.2 The Queue Interface 220
Example Use 222
4.3 Array-Based Queue Implementations 223
The ArrayBoundedQueue Class 223
The ArrayUnboundedQueue Class 230
4.4 An Interactive Test Driver 234
The General Approach 234
A Test Driver for the ArrayBoundedQueue Class 235
Using the Test Driver 235
4.5 Link-Based Queue Implementations 237
The Enqueue Operation 238
The Dequeue Operation 239
A Circular Linked Queue Design 241
Comparing Queue Implementations 242
4.6 Application: Palindromes 244
The Palindrome Class 244
The Applications 246
4.7 Queue Variations 248
Exceptional Situations 248
The GlassQueue 248
The Double-Ended Queue 251
Doubly Linked Lists 252
The Java Library Collection Framework Queue/Deque 255
4.8 Application: Average Waiting Time 257
Problem Discussion and Example 258
The Customer Class 259
The Simulation 262
Testing Considerations 268
4.9 Concurrency, Interference, and Synchronization 268
The Counter Class 270
Java Threads 271
Interference 274
Synchronization 275
A Synchronized Queue 277
Concurrency and the Java Library Collection Classes 282
Contents xv
Summary 283
Exercises 284
5 The Collection ADT 297
5.1 The Collection Interface 298
Assumptions for Our Collections 299
The Interface 299
5.2 Array-Based Collection Implementation 301
5.3 Application: Vocabulary Density 305
5.4 Comparing Objects Revisited 308
The equals Method 308
The Comparable Interface 314
5.5 Sorted Array-Based Collection Implementation 315
Comparable Elements 316
The Implementation 317
Implementing ADTs “by Copy” or “by Reference” 319
Sample Application 323
5.6 Link-Based Collection Implementation 325
The Internal Representation 325
The Operations 326
Comparing Collection Implementations 329
5.7 Collection Variations 330
The Java Collections Framework 330
The Bag ADT 331
The Set ADT 333
Summary 336
Exercises 337
6 The List ADT 345
6.1 The List Interface 346
Iteration 346
Assumptions for Our Lists 348
The Interface 348
6.2 List Implementations 350
Array-Based Implementation 350
Link-Based Implementation 355
6.3 Applications: Card Deck and Games 361
The Card Class 361
The CardDeck Class 363
Application: Arranging a Card Hand 366
Application: Higher or Lower? 369
Application: How Rare Is a Pair? 370
xvi Contents
6.4 Sorted Array-Based List Implementation 373
The Insertion Sort 374
Unsupported Operations 375
Comparator Interface 376
Constructors 377
An Example 378
6.5 List Variations 380
Java Library Lists 380
Linked List Variations 381
A Linked List as an Array of Nodes 381
6.6 Application: Large Integers 386
Large Integers 386
The Internal Representation 387
The LargeIntList class 388
The LargeInt Class 393
Addition and Subtraction 395
The LargeIntCLI Program 404
Summary 408
Exercises 410
7 The Binary Search Tree ADT 421
7.1 Trees 423
Tree Traversals 426
7.2 Binary Search Trees 429
Binary Trees 429
Binary Search Trees 431
Binary Tree Traversals 433
7.3 The Binary Search Tree Interface 435
The Interface 436
7.4 The Implementation Level: Basics 439
7.5 Iterative Versus Recursive Method Implementations 443
Recursive Approach to the size Method 444
Iterative Approach to the size Method 446
Recursion or Iteration? 448
7.6 The Implementation Level: Remaining Observers 448
The contains and get Operations 449
The Traversals 452
7.7 The Implementation Level: Transformers 455
The add Operation 455
The remove Operation 460
7.8 Binary Search Tree Performance 466
Text Analysis Experiment Revisited 466
Insertion Order and Tree Shape 468
Contents xvii
Balancing a Binary Search Tree 469
7.9 Application: Word Frequency Counter 471
The WordFreq Class 472
The Application 473
7.10 Tree Variations 479
Application-Specific Variations 479
Balanced Search Trees 482
Summary 485
Exercises 487
8 The Map ADT 499
8.1 The Map Interface 501
8.2 Map Implementations 506
Unsorted Array 506
Sorted Array 507
Unsorted Linked List 507
Sorted Linked List 508
Binary Search Tree 508
An ArrayList-Based Implementation 508
8.3 Application: String-to-String Map 512
8.4 Hashing 516
Collisions 518
8.5 Hash Functions 524
Array Size 524
The Hash Function 525
Java’s Support for Hashing 529
Complexity 530
8.6 A Hash-Based Map 530
The Implementation 531
Using the HMap class 538
8.7 Map Variations 539
A Hybrid Structure 540
Java Support for Maps 542
Summary 542
Exercises 543
9 The Priority Queue ADT 551
9.1 The Priority Queue Interface 552
Using Priority Queues 552
The Interface 553
9.2 Priority Queue Implementations 554
Unsorted Array 554
xviii Contents
Sorted Array 554
Sorted Linked List 556
Binary Search Tree 556
9.3 The Heap 556
9.4 The Heap Implementation 562
A Nonlinked Representation of Binary Trees 562
Implementing a Heap 564
The enqueue Method 567
The dequeue Method 569
A Sample Use 574
Heaps Versus Other Representations of Priority Queues 575
Summary 576
Exercises 576
10 The Graph ADT 583
10.1 Introduction to Graphs 584
10.2 The Graph Interface 588
10.3 Implementations of Graphs 591
Array-Based Implementation 591
Linked Implementation 596
10.4 Application: Graph Traversals 597
Depth-First Searching 598
Breadth-First Searching 602
10.5 Application: The Single-Source Shortest-Paths Problem 605
Summary 611
Exercises 612
11 Sorting and Searching Algorithms 621
11.1 Sorting 622
A Test Harness 623
11.2 Simple Sorts 625
Selection Sort 625
Bubble Sort 631
Insertion Sort 635
11.3 O(N log2N) Sorts 638
Merge Sort 639
Quick Sort 646
Heap Sort 652
11.4 More Sorting Considerations 658
Testing 658
Efficiency 658
Objects and References 660
Contents xix
Comparing Objects 661
Stability 661
11.5 Searching 662
Sequential Searching 663
High-Probability Ordering 663
Sorted Collections 664
Hashing 665
Summary 666
Exercises 667
Appendix A: Java Reserved Words 673
Appendix B: Operator Precedence 674
Appendix C: Primitive Data Types 675
Appendix D: ASCII Subset of Unicode 676
Glossary 677
Index 683
Object Oriented Data Structures Using Java 4th Edition Dale
CHAPTER
Getting Organized
Knowledge Goals
Youshouldbeableto
 describe some benefits of object-oriented programming
 describe the genesis of the Unified Method
 explain the relationships among classes, objects, and applications
 explain how method calls are bound to method implementations with respect to inheritance
 describe, at an abstract level, the following structures: array, linked list, stack, queue, list, tree, map, and graph
 identify which structures are implementation dependent and which are implementation independent
 describe the difference between direct addressing and indirect addressing
 explain the subtle ramifications of using references/pointers
 explain the use of O notation to describe the amount of work done by an algorithm
 describe the sequential search, binary search, and selection sort algorithms
Skill Goals
Youshouldbeableto
 interpret a basic UML class diagram
 design and implement a Java class
 create a Java application that uses the Java class
 use packages to organize Java compilation units
 create a Java exception class
 throw Java exceptions from within a class and catch them within an application that uses the class
 predict the output of short segments of Java code that exhibit aliasing
 declare, initialize, and use one- and two-dimensional arrays in Java, including both arrays of a primitive type and arrays of objects
 given an algorithm, identify an appropriate size representation and determine its order of growth
 given a section of code determine its order of growth
1
©
Ake13bk/Shutterstock
2 Chapter 1 Getting Organized
Before embarking on any new project, it is a good idea to prepare carefully—to “get
organized.” In this irst chapter that is exactly what we do. A careful study of the topics
of this chapter will prepare us for the material on data structures and algorithms, using
the object-oriented approach, covered in the remainder of the book.
1.1 Classes, Objects, and Applications
Software design is an interesting, challenging, and rewarding task. As a beginning student
of computer science, you wrote programs that solved relatively simple problems. Much
of your effort went into learning the syntax of a programming language such as Java: the
language’s reserved words, its data types, its constructs for selection and looping, and its
input/output mechanisms.
As your programs and the problems they solve become more complex it is important
to follow a software design approach that modularizes your solutions—breaks them into
coherent manageable subunits. Software design was originally driven by an emphasis on
actions. Programs were modularized by breaking them into subprograms or procedures/
functions. A subprogram performs some calculations and returns information to the call-
ing program, but it does not “remember” anything. In the late 1960s, researchers argued
that this approach was too limiting and did not allow us to successfully represent the
constructs needed to build complex systems.
Two Norwegians, Kristen Nygaard and Ole-Johan Dahl, created Simula 67 in 1967.
It was the irst language to support object-oriented programming. Object-oriented lan-
guages promote the object as the prime modularization mechanism. Objects represent
both information and behavior and can “remember” internal information from one use to
the next. This crucial difference allows them to be used in many versatile ways. In 2001,
Nygaard and Dahl received the Turing Award, sometimes referred to as the “Nobel Prize
of Computing,” for their work.
The capability of objects to represent both information (the objects have attributes)
and behavior (the objects have responsibilities) allows them to be used to represent “real-
world” entities as varied as bank accounts, genomes, and hobbits. The self-contained na-
ture of objects makes them easy to implement, modify, and test for correctness.
Object orientation is centered on classes and objects. Objects are the basic run-time
entities used by applications. An object is an instantiation of a class; alternatively, a class
deines the structure of its objects. In this section we review these object-oriented pro-
gramming constructs that we use to organize our programs.
Classes
A class deines the structure of an object or a set of objects. A class deinition includes
variables (data) and methods (actions) that determine the behavior of an object. The fol-
lowing Java code deines a Date class that can be used to create and manipulate Date
objects—for example, within a school course-scheduling application. The Date class can
be used to create Date objects and to learn about the year, month, or day of any particular
3
1.1 Classes, Objects, and Applications
Date object.1
The class also provides
methods that return the Lilian Day Num-
ber of the date (the code details have been
omitted—see the feature section on Lilian
Day Numbers for more information) and
return a string representation of the date.
//----------------------------------------------------------------------
// Date.java by Dale/Joyce/Weems Chapter 1
//
// Defines date objects with year, month, and day attributes.
//----------------------------------------------------------------------
package ch01.dates;
public class Date
{
protected int year, month, day;
public static final int MINYEAR = 1583;
// Constructor
public Date(int newMonth, int newDay, int newYear)
{
month = newMonth; day = newDay; year = newYear;
}
// Observers
public int getYear() { return year; }
public int getMonth() { return month; }
public int getDay(){ return day; }
public int lilian()
{
// Returns the Lilian Day Number of this date.
// Algorithm goes here. Code is included with the program files.
// See Lilian Day Numbers feature section for details.
}
@Override2
public String toString()
1
The Java library includes a Date class, java.util.Date. However, the familiar properties of dates make them a natural
example to use in explaining object-oriented concepts. Here we ignore the existence of the library class, as if we must design
our own Date class.
2
The purpose of @Override is discussed in Section 1.2“Organizing Classes.”
Authors’ Convention
Java-reserved words (when used as such), user-defined
identifiers, class and file names, and so on, appear in
this font throughout the entire text.
4 Chapter 1 Getting Organized
// Returns this date as a String.
{
return(month + / + day + / + year);
}
}
The Date class demonstrates two kinds of variables: instance variables and class vari-
ables. The instance variables of this class are year, month, and day declared as
protected int year, month, day;
Their values vary for each “instance” of an object of the class. Instance variables provide
the internal representation of an object’s attributes.
The variable MINYEAR is declared as
public static final int MINYEAR = 1583;
MINYEAR is deined as being static, and thus it is a class variable. It is associated di-
rectly with the Date class, instead of with objects of the class. A single copy of a class vari-
able is maintained for all objects of the class.
Remember that the final modiier states that a variable is in its inal form and can-
not be modiied; thus MINYEAR is a constant. By convention, we use only capital letters
when naming constants. It is standard procedure to declare constants as class variables.
Because the value of the variable cannot change, there is no need to force every object of a
class to carry around its own version of the value. In addition to holding shared constants,
class variables can be used to maintain information that is common to an entire class. For
example, a BankAccount class may have a class variable that holds the number of current
accounts.
In the Date class example, the MINYEAR con-
stant represents the irst full year that the widely
used Gregorian calendar was in effect. The idea
here is that programmers should not use the
class to represent dates that predate that year.
We look at ways to enforce this rule in Section 1.3
“Exceptional Situations,” where we discuss han-
dling exceptional situations.
The methods of the class are Date, getYear, getMonth, getDay, lilian, and
toString. Note that the Date method has the same name as the class. Recall that this
means it is a special type of method, called a class constructor. Constructors are used to
create new instances of a class—that is, to instantiate objects of a class. The other meth-
ods are classiied as observer methods, because they “observe” and return information
based on the instance variable values. Other names for observer methods are “accessor”
methods and “getters,” as in accessing or getting information. Methods that simply return
the value of an instance variable, such as getYear() in our Date class, are very common
and always follow the same code pattern consisting of a single return statement. For this
reason we will format such methods as a single line of code. In addition to constructors
Authors’ Convention
We highlight important terms that might be unfamiliar to
the student in green, the first time they are featured, to
indicate that their definition can be found in the glossary
in Appendix E.
5
1.1 Classes, Objects, and Applications
and observers, there is another general category of method, called a transformer. As you
probably recall, transformers change the object in some way; for example, a method that
changes the year of a Date object would be classiied as a transformer.
You have undoubtedly noticed the use of the access modiiers protected and public
within the Date class. Let us review the purpose and use of access modiiers. This dis-
cussion assumes you recall the basic ideas behind inheritance and packages. Inheritance
supports the extension of one class, called the superclass, by another class, called the sub-
class. The subclass “inherits” properties (data and actions) from the superclass. We say that
the subclass is derived from the superclass. Packages let us group related classes together
into a single unit. Inheritance and packages are both discussed more extensively in the next
section.
Java allows a wide spectrum of access control, as summarized in Table 1.1. The public
access modiier used with the methods of Date makes them “publicly” available; any code
that can “see” an object of the class can use its public methods. We say that these methods
are “exported” from the class. Additionally, any class that is derived from the Date class us-
ing inheritance inherits its public methods and variables.
Public access sits at one end of the access spectrum, allowing open access. At the other
end of the spectrum is private access. When you declare a class’s variables and methods as
private, they can be used only inside the class itself and are not inherited by subclasses.
You should routinely use private (or protected) access within your classes to hide their
data. You do not want the data values to be changed by code that is outside the class. For
example, if the month instance variable in our Date class was declared to be public,
then the application code could directly set the value of a Date object’s month to strange
numbers such as −12 or 27.
An exception to this guideline of hiding data within a class is shown in the Date ex-
ample. Notice that the MINYEAR constant is publicly accessible. It can be accessed directly
by the application code. For example, an application could include the statement
if (myYear  Date.MINYEAR) ...
Because MINYEAR is a inal constant, its value cannot be changed by the application. Thus,
even though it is publicly accessible, no other code can change its value. It is not necessary
Table 1.1 Java Access Control Modifiers
Access Is Allowed
Within
the Class
Within
the Package
Within
Subclasses Everywhere
public X X X X
protected X X X
package X X
private X
6 Chapter 1 Getting Organized
to hide it. The application code above also shows how to access a public class variable
from outside the class. Because MINYEAR is a class variable, it is accessed through the
class name, Date, rather than through an object of the class.
Private access affords the strongest protection. Access is allowed only within the
class. However, if you plan to extend your classes using inheritance, you may want to use
protected access instead.
The protected access modiier used in
Date provides visibility similar to private access,
only slightly less rigid. It “protects” its data from
outside access, but allows the data to be accessed
from within its own package or from any class
derived from its class. Therefore, the methods within the Date class can access year,
month, and day, and if, as we will show in Section 1.2 “Organizing Classes,” the Date class
is extended, the methods in the extended class can also access those variables.
The remaining type of access is called package access. A variable or method of a class
defaults to package access if none of the other three modiiers are used. Package access
means that the variable or method is accessible to any other class in the same package.
1582 1582
OCTOBER
SUN
31
17
24
MON
1
18
25
TUE
2
19
26
WED
3
20
27
THU
4
21
28
FRI
15
22
29
SAT
16
23
30
Coding Convention
We use protected access extensively for instance
variables within our classes in this text.
Lilian Day Numbers
Various approaches to numbering days have been proposed. Most choose a particular day in history
as day 1, and then number the actual sequence of days from that day forward with the numbers 2,
3, and so on. The Lilian Day Number (LDN) system uses October 15, 1582, as day 1, or LDN 1.
Our current calendar is called the Gregorian calendar. It was established in 1582 by Pope Greg-
ory XIII. At that time 10 days were dropped from the month of October, to make up for small errors
that had accumulated throughout the years. Thus, the day following October 4, 1582, in the Gre-
gorian calendar is October 15, 1582, also known as LDN 1 in the Lilian day numbering scheme. The
scheme is named after Aloysius Lilius, an advisor to Pope Gregory and one of the principal instigators
of the calendar reform.
Originally, Catholic European countries adopted the Gregorian calendar. Many Protestant na-
tions, such as England and its colonies, did not adopt the Gregorian calendar until 1752, at which
1582 1582
OCTOBER
SUN
31
17
24
MON
1
18
25
TUE
2
19
26
WED
3
20
27
THU
4
21
28
FRI
15
22
29
SAT
16
23
30
Lilian Day Numbers
Various approaches to numbering days have been proposed. Most choose a particular day in history
as day 1, and then number the actual sequence of days from that day forward with the numbers 2,
3, and so on. The Lilian Day Number (LDN) system uses October 15, 1582, as day 1, or LDN 1.
Our current calendar is called the Gregorian calendar. It was established in 1582 by Pope Greg-
ory XIII. At that time 10 days were dropped from the month of October, to make up for small errors
that had accumulated throughout the years. Thus, the day following October 4, 1582, in the Gre-
gorian calendar is October 15, 1582, also known as LDN 1 in the Lilian day numbering scheme. The
scheme is named after Aloysius Lilius, an advisor to Pope Gregory and one of the principal instigators
of the calendar reform.
Originally, Catholic European countries adopted the Gregorian calendar. Many Protestant na-
tions, such as England and its colonies, did not adopt the Gregorian calendar until 1752, at which
7
1.1 Classes, Objects, and Applications
The Unified Method
The object-oriented approach to programming is based on implementing models of real-
ity. But how do you go about this? Where do you start? How do you proceed? The best plan
is to follow an organized approach called a methodology.
In the late 1980s, many people proposed object-oriented methodologies. By the mid-
1990s, three proposals stood out: the Object Modeling Technique, the Objectory Process,
and the Booch Method. Between 1994 and 1997, the primary authors of these proposals
got together and consolidated their ideas. The resulting methodology was dubbed the
Uniied Method. It is now, by far, the most popular organized approach to creating object-
oriented systems.
The Uniied Method features three key elements:
1. It is use-case driven. A use-case is a description of a sequence of actions performed
by a user within the system to accomplish some task. The term “user” here should be
interpreted in a broad sense and could represent another system.
2. It is architecture-centric. The word “architecture” refers to the overall structure of the
target system, the way in which its components interact.
time they also “lost” 11 days. Today, most countries use the Gregorian calendar, at least for official
international business. When comparing historical dates, one must be careful about which calendars
are being used.
In our Date class implementation, MINYEAR is 1583, representing the first full year during
which the Gregorian calendar was in operation. We assume that programmers will not use the
Date class to represent dates before that time, although this rule is not enforced by the class. This
assumption simplifies calculation of day numbers, as we do not have to worry about the phantom
10 days of October 1582.
To calculate LDNs, one must understand how the Gregorian calendar works. Years are usually
365 days long. However, every year evenly divisible by 4 is a leap year, 366 days long. This aligns the
calendar closer to astronomical reality. To fine-tune the adjustment, if a year is evenly divisible by
100, it is not a leap year but, if it is also evenly divisible by 400, it is a leap year. Thus 2000 was a
leap year, but 1900 was not.
Given a date, the lilian method of the Date class counts the number of days between that
date and the hypothetical date 1/1/0—that is, January 1 of the year 0. This count is made under the
assumption that the Gregorian reforms were in place during that entire time period. In other words,
it uses the rules described in the previous paragraph. Let us call this number the Relative Day Number
(RDN). To transform a given RDN to its corresponding LDN, we just need to subtract the RDN of
October 14, 1582, from it. For example, to calculate the LDN of July 4, 1776, the method first cal-
culates its RDN (648,856) and then subtracts from it the RDN of October 14, 1582 (578,100), giving
the result of 70,756.
Code for the lilian method is included with the program code files.
time they also “lost” 11 days. Today, most countries use the Gregorian calendar, at least for official
international business. When comparing historical dates, one must be careful about which calendars
are being used.
In our Date class implementation, MINYEAR is 1583, representing the first full year during
which the Gregorian calendar was in operation. We assume that programmers will not use the
Date class to represent dates before that time, although this rule is not enforced by the class. This
assumption simplifies calculation of day numbers, as we do not have to worry about the phantom
10 days of October 1582.
To calculate LDNs, one must understand how the Gregorian calendar works. Years are usually
365 days long. However, every year evenly divisible by 4 is a leap year, 366 days long. This aligns the
calendar closer to astronomical reality. To fine-tune the adjustment, if a year is evenly divisible by
100, it is not a leap year but, if it is also evenly divisible by 400, it is a leap year. Thus 2000 was a
leap year, but 1900 was not.
Given a date, the lilian method of the Date class counts the number of days between that
date and the hypothetical date 1/1/0—that is, January 1 of the year 0. This count is made under the
assumption that the Gregorian reforms were in place during that entire time period. In other words,
it uses the rules described in the previous paragraph. Let us call this number the Relative Day Number
(RDN). To transform a given RDN to its corresponding LDN, we just need to subtract the RDN of
October 14, 1582, from it. For example, to calculate the LDN of July 4, 1776, the method first cal-
culates its RDN (648,856) and then subtracts from it the RDN of October 14, 1582 (578,100), giving
the result of 70,756.
Code for the lilian method is included with the program code files.
8 Chapter 1 Getting Organized
3. It is iterative and incremental. The Uniied Method involves a series of development
cycles, with each one building upon the foundation established by its predecessors.
One of the main beneits of the Uniied Method is improved communication among the
people involved in the project. The Uniied Method includes a set of diagrams for this
purpose, called the Uniied Modeling Language (UML).3
UML diagrams have become a
de facto industry standard for modeling software. They are used to specify, visualize, con-
struct, and document the components of a software system. We use UML class diagrams
throughout this text to model our classes and their interrelationships.
A diagram representing the Date class is shown in Figure 1.1. The diagram follows
the standard UML class notation approach. The name of the class appears in the top sec-
tion of the diagram, the variables (attributes) appear in the next section, and the meth-
ods (operations) appear in the inal section. The diagram includes information about the
nature of the variables and method parameters; for example, we can see at a glance that
year, month, and day are all of type int. Note that the variable MINYEAR is underlined;
this indicates that it is a class variable rather than an instance variable. The diagram also
indicates the visibility or protection associated with each part of the class (+ = public, #
= protected).
Objects
Objects are created from classes at run time. They can contain and manipulate data. Mul-
tiple objects can be created from the same class deinition. Once a class such as Date has
been deined, a program can create and use objects of that class. The effect is similar to
expanding the language’s set of standard types to include a Date type. To create an object
in Java we use the new operator, along with the class constructor, as follows:
Date myDate = new Date(6, 24, 1951);
Date yourDate = new Date(10, 11, 1953);
Date ourDate = new Date(6, 15, 1985);
Figure 1.1 UML class diagram for the Date class
Date
#year:int
#month:int
#day:int
+MINYEAR:int = 1583
+Date(newMonth:int,newDay:int,newYear:int)
+getYear():int
+getMonth():int
+getDay():int
+lilian():int
+toString():String
3
The official definition of the UML is maintained by the Object Management Group. Detailed information can be found at
http://www.uml.org/.
Random documents with unrelated
content Scribd suggests to you:
CHAPTER III
MRS. FABIAN'S VISIT
Eliza was not obliged to give up the apartment until the end of the
month. Hence her drifting from day to day, and Pluto's naps in the
lap of luxury.
All her energy and systematic habits were in a state of suspension.
Her clocks ran down. The watch in the tiny satin slipper beside her
bed alone ticked the minutes away, and when Eliza wound it her
eyes were too wet to see the time. Night fell and she went to bed.
Morning dawned and she arose. She drank tea, but it was too much
trouble to eat.
One day the bell rang. At first she determined not to answer it. Then
second thought came to her. What was she waiting here for except
to answer the bell? Was her next duty not to introduce the usurper
into his kingdom—to give into his desecrating hands those objects,—
easel, palette, brushes, paints,—hallowed by her dear one's use? At
the sound of a knock she hastened to fling open the door. Mrs.
Fabian, elegantly gowned and furred, stood before her.
Eliza gazed at this apparition dumb.
Why, Eliza Brewster, exclaimed the visitor with concern, I scarcely
knew you. After the mutual gaze of astonishment the caller moved
in with her air of stately assurance, and Eliza followed her perforce
into the living-room. Here Mrs. Fabian swiftly examined the
possibilities of the scanty chairs, then seated herself in the largest.
You have been ill, too, Eliza? You look like a ghost!
The gaunt woman in the alpaca dress, so filled with resentment that
she begrudged her own tears because they informed this relative
of her grief, stood in silence with a beating heart.
Sit down, you poor creature, went on Mrs. Fabian, unsuspecting
hidden fires.
They burned higher at the tone of patronage, but Eliza, weakened
from mourning and lack of food, felt her knees trembling and sank
into the nearest chair.
Mrs. Fabian, genuinely touched by the ravages she saw, broke the
silence that followed.
I was greatly surprised and shocked to hear of Aunt Mary's sudden
going.
She began to feel uncomfortable under the set gaze of Eliza's
swollen eyes.
I suppose you sent to my house at once, and found that Mr. Fabian
and I were in the far West.
No, I didn't think of sending, returned Eliza.
You should have done so. Surely there was no one nearer to Aunt
Mary than I.
It was in the paper, said Eliza dully.
Had I been here I should, of course, have taken charge of the
funeral.
The pale eyes emitted a curious light.
No, you wouldn't, Mrs. Fabian, was the quiet reply.
Why do you say that?
Because the time for you to have done something for Mrs. Ballard
was while she was alive.
Eliza was too spent physically to speak other than softly, but her
words brought the amazed color to her visitor's face.
You are presuming, Mrs. Fabian said, after a moment. What do
you know about it? I suppose Aunt Mary did not think it worth while
to tell you all the things I did for her.
No, agreed Eliza, she never said a word about the times you came
with your automobile to take her riding; nor the picture exhibitions
you took her to see, or the way you had her to dinner Thanksgivin'
time and other times, or how you had her to spend part o' the
summer with you at the island, or—
Eliza Brewster, what does this mean! Mrs. Fabian's eyes were
dilated. Aunt Mary was not related to my husband or to his children.
I never expected him to marry my family.
Miss Brewster's gaze was fixed upon the speaker with pale scorn,
but the latter continued with what she endeavored to make a
dignified defence. I always sent Aunt Mary a present at Christmas.
Yes, interrupted Eliza. Last season 'twas a paper-cutter. You gave
her cuts enough without that.
And I called upon her at intervals, continued the visitor in a
heightened tone to drown the small voice.
Intervals of a year, said Eliza.
Mrs. Fabian started to rise, but bethought herself, and sank back.
You are impertinent, she said coldly. A person in your position
cannot understand the duties of one in mine. There can be no
discussion between you and me. The speaker stirred in her chair
and collected herself. I—and every one of Aunt Mary's relatives—
appreciate your faithful service to her, and thank you for it.
Don't you dare! ejaculated Eliza, with such sudden belligerency
that Mrs. Fabian started.
You're almost crazed with fatigue and grief, poor creature, she said
at last. I can see that you are scarcely responsible for what you say
to-day. You must take a long rest. Shall you go home to the island or
take another place in town? I can find you one.
Mrs. Fabian felt the superiority of her own self-control as she made
this kind offer; besides, in these troublous days with servants,
steady, reliable Eliza, with a sure touch in cookery, was not to be
despised. The visitor accompanied her offer with a soothing attempt
at a smile.
Eliza had relapsed into dullness. I won't trouble you, she said.
It would not be any trouble, was the magnanimous reply. Just let
me know any time when you would like a reference, Eliza. It will
give me pleasure to reward your faithfulness.
Mrs. Fabian loved approval quite as much as she did admiration. She
would feel much more comfortable to win that of even this
uncompromising, cranky individual, so lined with the signs of
suffering. As Eliza Brewster was a native of the island where Mrs.
Fabian had resorted from the days of her girlhood, she had a very
slight but old acquaintance with this woman. As she glanced at the
thin hair, now fast turning grey, the sunken eyes and cheeks, and
the bony, roughened hands, she shuddered beneath her ermine-
lined sables, to remember that she and Eliza Brewster were about
the same age. She passed a white-gloved hand over the firm
contour of her smooth cheek as if to make sure of its firmness. I
believe it was I who recommended you to Aunt Mary in the first
place, long ago, she added.
That's one o' your mistakes, said Eliza drily.
On the contrary, returned Mrs. Fabian graciously. She was
determined to warm this forlorn specimen of New England frigidity
into something humanly companionable, else how was she going to
attain the object of her visit? She went on with such flattery of
manner as she might have employed toward a desirable débutante.
It has proved quite the best thing that I ever did for Aunt Mary;
securing her comfort and thereby the peace of mind of all who
belonged to her. Don't call it a mistake, Eliza.
However that may be, returned the other immovably, 't wa'n't you
that did it. 'Twas your Cousin Mary.
Oh—was it? Oh, indeed? responded Mrs. Fabian, slipping back her
furs still further. Eliza Brewster's disagreeable manner was making
her nervous. Yes, I believe Mrs. Sidney was with us on her
wedding-trip just at that time. Mr. Fabian and I have just returned
from visiting Mrs. Sidney out in her wild mountain home.
Eliza's eyes roved involuntarily to two blank sheets of board standing
on the mantelpiece; but she was silent.
Do you know the contents of Aunt Mary's will, Eliza? asked Mrs.
Fabian, after waiting vainly for an inquiry as to her cousin's well-
being.
I do.
What do you think of it?
That don't matter, does it?
A streak of light illumined Mrs. Fabian's annoyance. Ah, that was
what was the matter with Eliza. After twenty-five years of faithful
service, she had expected to inherit her mistress's few hundreds.
Full explanation, this, of the present sullenness. The disappointment
must, indeed, have been bitter.
Mrs. Fabian felt an impulse of genuine sympathy. She knew the
singular loneliness of Eliza's situation; knew that she had no near
kin, and the transplanting from the island home had been complete.
What an outlook now, was Eliza Brewster's!
Perhaps the will was as much of a surprise to you as it was to the
rest of us, Mrs. Fabian went on. The Sidneys were amazed. They
didn't tell me just how much Aunt Mary left young Mr. Sidney. Do
you know?
Yes, replied Eliza promptly.
And again Mrs. Fabian looked at her interrogatively. As well question
the Sphinx. She comprehended the stony closing of the thin lips.
There might be a combination which would make them open, but
she did not have it. She shrugged her fine-cloth shoulders. Oh, well,
it doesn't matter. It must have been very little, anyway.
She sighed. She must get at her business, though she dreaded
absurdly to introduce it. Well, Eliza, if you will take me to Aunt
Mary's room, I will go through her belongings. It is always the most
painful duty connected with a death, but it cannot be escaped.
Eliza stared at her, speechless.
Aunt Mary had a few very nice things, went on Mrs. Fabian. She
tried to smile as at a loving memory. The regulation treasures of a
dear old lady,—her diamond ring, a diamond brooch, and a camel's
hair shawl—My heavens! cried the visitor, interrupting herself
suddenly with a shriek of terror. Take it away! Take it away!
She clung to the back of her chair; for Pluto, silent as a shadow, had
sprung upon the ends of her pelerine as they lay in her lap and was
daintily nosing the fur, while perilously grasping its richness, his eyes
glowing with excitement. Eliza rose, and sweeping him into one arm
resumed her seat.
Oh, how that frightened me! Mrs. Fabian panted and looked
angrily at the animal with the jetty coat and abbreviated tail, whose
eyes, live emeralds, expanded and contracted as they glowed still
upon the coveted fur.
If she expected an apology, none came. Eliza's pale face showed no
emotion. Endurance was written in every line.
To be interrupted at such a critical moment! Mrs. Fabian felt it was
unbearable.
Let me see—she began again with a little laugh. Your pet knocked
everything out of my head, Eliza. Oh, yes, I was saying that I will
look over Aunt Mary's things now.
She rose as she spoke. Eliza kept her seat.
You can't do that, Mrs. Fabian.
I certainly shall, Eliza Brewster. What do you mean?
I mean that they're mine. She left 'em all to me.
The speaker struggled to control the trembling of her lips.
The visitor looked the limp black alpaca figure over, haughtily.
Aunt Mary left you her diamond ring, her diamond brooch, and her
camel's hair shawl? she asked sceptically.
She left her diamond brooch to her namesake, Mrs. Sidney. I sent it
to her a week ago.
Then, since you know Aunt Mary's wishes, what did she leave me?
The ring?
No, ma'am!
The shawl?
No, ma'am.
Mrs. Fabian's nostrils dilated.
My aunt's poor trifles are nothing to me, of course, except for
sentiment's sake, she said haughtily.
Eliza bowed her bitter face over Pluto's fur.
I am quite sure, however, that she did not pass away without some
mention of me,—her sister's child.
She did, though, Mrs. Fabian. If it's a keepsake you want, added
Eliza drily, you may have the paper-cutter. It's never been out o' the
box.
The visitor, still standing, eyed the other with compressed lips before
she spoke:—
I have told you that I don't consider you responsible to-day. You are
half-crazed, and I'm sorry for you. Answer me this, however, and
mind, I shall verify your words by a visit to Mrs. Ballard's lawyer. Did
my aunt leave you, legally, all her personal possessions?
She did.
Mrs. Fabian maintained another space of silence, gazing at the
seated figure, whose gown looked rusty behind the polished lynx-
black pressed against it. There was no mistaking the truth in the
pale, wretched eyes.
Disappointed about the money, though, and taking out her ill
temper on me, thought the visitor.
To Eliza's increased heaviness of heart, the lady resumed her seat.
Aunt Mary's death was sudden and unexpected and that explains
her not speaking of me, she said; but I know it would please her
that I should use something that she had owned. I remember that
shawl as being a very good one. It came to her from some of her
husband's people. I'll buy that of you, Eliza.
Will you? returned the other, and Pluto emitted an indignant yowl
and tried to leap from the tightening hold.
Don't you let him go, Eliza! cried Mrs. Fabian in a panic. He's
crazy about my fur. They always are.—Yes, the shawl is of no use to
you and the money will be. It is so fine, it would be wicked to cut it
into a wrap. I shall spread it on my grand piano.
Silence, while Eliza struggled still to control the trembling lips, and
Pluto twisted to escape her imprisoning arm.
I'm willing to give you twenty-five dollars for that shawl.
Mrs. Fabian waited, and presently Eliza spoke:—
It ain't enough, she said, against her impeding breath.
Fifty, then. We all feel grateful to you.
Mrs. Fabian, Eliza sat up in her chair as if galvanized and looked
her visitor in the eyes, while she spoke with unsteady solemnity, the
price o' that shawl is one million dollars.
The visitor stared at the shabby figure with the grey, unkempt locks,
then shrugged her shoulders with a smile. You'll come to your
senses, Eliza, she said. Some day that fifty dollars will look very
good to you. I'll hold the offer open—
Likewise, added Eliza, breaking in upon her words with heightened
voice, but the same deliberation, that is the price of each
handkerchief she left me, and each one of her little, wornout
slippers, and her—
She could get no further. She choked. Mrs. Fabian rose; Pluto, with
another cry and a supreme writhe, tore himself from his iron prison.
The visitor shuddered, and looked at him fearfully, as his eager eyes
seemed to threaten her. She hastened precipitately toward the door.
Eliza, putting the utmost constraint upon herself, rose and ushered
her out.
Mrs. Fabian uttered a brief good-bye. Eliza was beyond speech.
While the visitor entered her waiting car, and sank with relief among
its cushions, the mourner stood, her back against the closed door,
and her eyes closed.
Restrained drops ran down her cheeks in well-worn ruts, and
occasionally a spasmodic sob shook the slight form.
Pluto came to her feet, his short tail stiffly outstretched and his half-
closed eyes lifted to the sightless face. In the long silence he rubbed
himself against her feet in token of forgiveness.
CHAPTER IV
PHILIP SIDNEY
The Fabians had given Philip Sidney a pressing invitation to spend
his first week in New York with them. When he arrived, however,
and announced himself at the house, through some
misunderstanding there was no one there to receive him save the
servants.
A comely maid apologized for the absence of her mistress, saying
that Mr. Sidney had not been expected until the following day; and
showing him to his room she left him to his own devices.
Emerging from his bath and toilet, he found Mrs. Fabian not yet
returned. It was but four o'clock, and he decided to go to the Ballard
apartment and attend to his errand there.
Eliza had been doing some sweeping, the need for it goading her
New England conscience to action. Her brown calico dress was
pinned up over her petticoat, and her stern, lined face looked out
from a sweeping-cap.
There sounded suddenly a vigorous knock on her door.
She scowled. Some fresh agent, I s'pose, she thought. Too sly to
speak up the tube.
Broom in hand, she strode to the door and pulled it open with swift
indignation.
Why didn't you ring? she exclaimed fiercely. We don't want—
She paused, her mouth open, and stared at the young man who
pulled off a soft felt hat, and looked reassuring and breezy as he
smiled.
I did ring, but it was the wrong apartment. There was no card
downstairs, so I started up the trail. Is this Mrs. Ballard's?
The frank face, which she instantly recognized, and the clear voice
that had a non-citified deliberation, accused Eliza of lack of
hospitality; and she suddenly grew intensely conscious of her cap
and petticoat.
Come in, she said. I was doin' some sweepin'. The first— she
paused abruptly and led the way down the corridor to the shabby
living-room.
Phil's long steps followed her while his eyes shone with appreciation
of the drum-major effect of the cap and broom, and the memory of
his fierce greeting.
I don't wonder Aunt Mary died, he thought. I would too.
Meanwhile Eliza's heart was thumping. This interview was the climax
of all she had dreaded. The usurper had an even more manly and
attractive exterior than she had expected, but well she knew the
brutal indifference of youth; the selfishness that takes all things for
granted, and that secretly despises the treasures of the old.
The haste with which she set the broom in the corner, unpinned her
dress, and pulled off her cap, was tribute to the virile masculinity of
the visitor; but the stony expression of her face was defence from
the blows which she felt he would deliver with the same airy
unconsciousness that showed in the swing of his walk.
You're Eliza Brewster, I'm sure, he said. My mother knew you
when she was a girl.
The hasty removal of Eliza's cap had caused a weird flying-out of her
locks. The direct gaze bent upon her twinkled.
I wonder if she'd let me paint her as Medusa, he was thinking;
while her unspoken comment was: And she never saw his teeth!
It's just as well.
Yes, that's who I am, she said. Sit down, Mr. Sidney. I've been
expectin' you.
You didn't behave that way, he replied good-naturedly, obeying. I
thought at first I was going downstairs quicker than I came up, and
I'd taken them three at a time.
His manner was disarming and Eliza smoothed her flying locks.
The agents try to sneak around the rules o' the house, she said
briefly.
So this is where Aunt Mary lived. He looked about the room with
interest. We people in God's country hear about these flats where
you don't dare keep a dog for fear it'll wag its tail and knock
something over.
The troublesome lump in Eliza's throat had to be swallowed, so the
visitor's keen glance swept about the bare place in silence.
I see she didn't go in much for jim-cracks, he added presently.
Eliza's lump was swallowed. Mrs. Ballard didn't care for common
things, she said coldly. She was an artist.
Phil comprehended vaguely that rebuke was implied, and he met the
hard gaze as he hastened to reply:—
Yes, yes, I understand. An increase of the pathos he had always
discerned since learning about his great-aunt, swept over him now,
face to face with the meagreness of her surroundings. Did Aunt
Mary work in this room? I see an easel over there.
Yes, she worked here. The reply came in an expressionless voice.
Poor Aunt Mary! thought the visitor. No companion but this
image!
Eliza exerted heroic self-control as she continued: I've got the
things packed up for you—the paints, and brushes, and palette. The
easel's yours, too. Do you want to take 'em to-day?
Would it be a convenience to you if I did? Are you going to give up
the flat immediately?
In a week.
Then I'll leave them a few days if you don't mind while I'm looking
for a room. I haven't an idea where to go. I'm more lost here than I
ever was in the woods; but the Fabians will advise me, perhaps. Mrs.
Fabian has been here to see you, I suppose.
Eliza's thin lips parted in a monosyllable of assent.
What a wooden Indian! thought Phil. Nevertheless, being a genial
soul and having heard Miss Brewster's faithfulness extolled, he
talked on: We hear about New York streets being canyons. They are
that, and the sky-line is amazing; but the noise,—great heavens,
what a racket! and I can't seem to get a breath.
The young fellow rose restlessly, throwing back his shoulders, and
paced the little room, filling it with his mountain stride.
Eliza Brewster watched him. She thought of her mistress, and the
pride and joy it would have been to her to receive this six feet of
manhood under her roof.
She wouldn't 'a' kept her sentimental dreams long, reflected Eliza
bitterly. He'd 'a' hurt her, he'd 'a' stepped on her feelin's and never
known it. He walks as if he had spurs on his boots. She steeled
herself against considering him through Mrs. Ballard's eyes. He's
better-lookin' than the picture, she thought, and I wouldn't trust a
handsome man as far as I could see him. They haven't any business
with beauty and it always upsets 'em one way or another—yes,
every time.
Her eyes wandered to the mantelpiece whose bareness was relieved
only by three varying sized pieces of blank paper. She felt the
slightest quiver of remorse as she looked. She seemed to see her
mistress's gentle glance filled with rebuke.
She stirred in her chair, folded her arms, and cleared her throat.
You can leave the things here till I go, if you want to, she said.
Phil paused in his promenade and regarded her. Her manner was so
unmistakably inimical that for the first time he wondered.
Perhaps, after all, she was not just a machine. And the same
thought which had been entertained by Mrs. Fabian occurred to him.
Twenty-five years of faithful service, he reflected. I wonder if she
expected the money? She's sore at me. That's a cinch.
Phil's artist nature grasped her standpoint in a flash. The granite
face, with its signs of suffering, the loneliness, the poverty, all
appealed to him to excuse her disappointment.
His eyes swept about the bare walls.
Where are Aunt Mary's pictures? he asked. Was she too modest
to hang them?
There were some up there, replied Eliza. I took 'em down.
The visitor's quick eyes noted the white boards on the mantelpiece.
With an unexpected movement, he strode across to it, and turned
them around.
He stood in the same position for a space.
Great guns, but she hates me! he thought, while Eliza, startled,
felt the shamed color stream up to her temples.
What would Mrs. Ballard say! was her guilty reflection.
Pluto here relieved the situation by making a majestic entrance. His
jewel eyes fixed on the stranger for a moment with blinking
indifference, then he proceeded, with measured tread, toward the
haven of his mistress's lap.
Hello, Katze, said Phil, stooping his scarlet face. He seized the
creature by the nape of its neck and instantly the amazed cat was
swung up to his broad shoulder, where it sat, claws digging into his
coat and eyes glowering into his own.
Say, charcoal would make a white mark on you, pussy, he went on,
smoothing the creature in a manner which evidently found favor, for
Pluto did not offer to stir.
When I'm not doing her as Medusa, he reflected, I'll paint her as
a witch with this familiar. She'll only have to look at the artist to get
the right expression.
A distinguished visitor from the island of Manx, I suspect, he said
aloud.
No, returned Eliza, still fearfully embarrassed. Pluto was born right
here in New York.
The ever-ready stars in the visitor's eyes twinkled again into the
green fire opposite them.
It was his tail I was noticing. Manx cats are like that.
Oh, that was boys. If I could 'a' caught 'em I'd 'a' liked to cut off
their arms.
I'll bet on that, thought Phil, and their legs too.
Eliza cleared her throat. She seemed still to see the gentle eyes of
her lost one rebuking her. With utter disregard of a future state she
was preparing a lie.
About those sketches, she said presently, and such was her
hoarseness that she was obliged to clear her throat again, you see,
I was—sweepin', and I turned 'em to the wall.
Oh, yes, said Phil, and continued to smooth Pluto who purred
lustily. A pretty good one for New England, he thought; and
carelessly turning the third card about, he came face to face with his
own photograph.
With one glance of disgust he tore the picture in two and threw it
down.
Eliza started. What did you do that for? she demanded sharply.
Phil made a motion of impatience.
Oh, it's so darned pretty! he explained. I thought all those
pictures were in the fire.
Mrs. Ballard set great store by that, said Eliza coldly, and by the
sketches, too, she added.
She was sitting up stiffly in her chair, now, and her gaze fixed on
Phil, as, her cat on his shoulder singing loud praise of his fondling
hand, he came and stood before her.
I wish you'd let me see some of Aunt Mary's pictures, he said.
The dead woman's letter was against his heart. He felt that they
were standing together, opposed to the hard, grudging face
confronting him.
But this was Eliza's crucial moment. In spite of herself she feared in
the depths of her heart that that which Mrs. Ballard had said was
true; that this restless, careless boy had an artistic ability which her
dear one had never attained. She shrank with actual nausea from his
comments on her mistress's work. He might not say anything
unkind, but she should see the lines of his mouth, the quiver of an
eyelash.
She felt unable to rise.
She left 'em all to me, she said mechanically, pale eyes meeting
dark ones.
Phil brushed Pluto's ears and the cat sang through the indignity.
Talk about the bark on a tree! he thought. I believe I'll paint her
as a miser, after all! She'd be a wonder, with Pluto standing guard,
green eyes peering out of the shadow.
He smiled down at Eliza, the curves of his lips stretching over the
teeth she had admired.
All right, he said. I'm not going to take them away from you.
Eliza forced herself to her feet, and without another word slowly left
the room.
Phil met the cat's blinking eyes where the pupils were dilating and
contracting. Katze, this place gives me the horrors! he confided.
More than once on the train he had read over his aunt's letter, and
each time her words smote an answering chord in his heart and set
it to aching.
The present visit accentuated the perception of what her life had
been. For a moment his eyes glistened wet against the cat's indolent
contentment.
I wish she hadn't saved any money, the poor little thing, he
muttered. No friends, no sympathy—nothing but that avaricious
piece of humanity, calculating every day, probably, on how soon she
would get it all. I'll paint her as a harpy. That's what I'll do. Talons of
steel! That's all she needs. He heard a sound and dashed a hand
across his eyes.
Eliza, heavy of heart, stony of face, entered, a number of pictures
bound together, in her hands. The visitor darted forward to relieve
her, and Pluto drove claws into his suddenly unsteady resting-place.
Eliza yielded up her treasures like victims, and stood motionless
while Phil received them. Never had she looked so gaunt and grey
and old; but the visitor did not give her a glance. Aunt Mary's letter
was beating against his heart. Here was the work her longing hands
had wrought, here the thwarting of her hopes.
His fingers were not quite steady as he untied the strings, and
moving the easel into a good light placed a canvas upon it.
Eliza did not wish to look at him, but she could not help it. Her pale
gaze fixed on his face in a torture of expectation, as he backed away
from the easel, his eyes on the picture.
Pluto rubbed against his ear as a hint that caressing be renewed.
He stood in silence, and Eliza could detect nothing like a smile on his
face.
Presently he removed the canvas, and took up another. It was the
portrait of Pluto.
Hello, Katze. Got your picture took, did you? Aunt Mary saw your
green shadows all right.
He set the canvas aside, and took up another. Eliza's muscles ached
with tension. Her bony hands clasped as she recognized the picture.
To the kittens over the table in the kitchen she had once confided
that this landscape, which the artist had called Autumn, looked to
her eyes like nothing on earth but a prairie fire! It had been a
terrible moment of heresy. She was punished for it now.
Phil backed away from the canvas, and elbow in his hand, rested his
finger on his lips for what seemed to Eliza an age. Her heart
thumped, but she could not remove her gaze from him.
Pluto, finding squirming and rubbing of no avail, leaped to the floor
and blinked reflectively at his mistress. A flagpole would have
offered equal facilities for cuddling.
He therefore made deliberate selection of the least unsatisfactory
chair, and with noiseless grace took possession.
Phil nodded. Yes, sir, he murmured; yes, sir.
Eliza's teeth bit tighter on her suffering under lip. What did Yes, sir
mean? At least he was not smiling.
He went on, slightly nodding, and thinking aloud; Aunt Mary was
ahead of her time. She knew what she was after.
Eliza tried to speak, and couldn't. Something clicked in her throat.
Phil went on regarding the autumnal tangle, and with a superhuman
effort Eliza commanded her tongue.
What was that you said, Mr. Sidney?
Phil, again becoming conscious of the stony presence, smiled a little.
Aunt Mary would have found sympathizers in Munich, he said.
That's Germany, ain't it? said Eliza, words and breath interlocking.
Yes. Most of Uncle Sam's relatives want to see plainer what's doing;
at least those who are able to buy pictures.
Ahead of her time! gasped Eliza, her blood racing through her
veins. Ought to 'a' been in Germany!
And then the most amazing occurrence of Philip Sidney's life took
place. There was a rush toward him, and suddenly his Medusa, his
witch, his miser, his harpy was on her knees on the floor beside him,
covering his hand with tears and kisses, and pouring out a torrent of
words.
I've nearly died with dread of you, Mr. Sidney. Oh, why isn't she
here to hear you say those words of her pictures! Nobody was ever
kind to her. Her relations paid no more attention to her, or her work,
than if she'd been a—a—I don't know what. She was poor, and too
modest, and the best and sweetest creature on earth; and when
your sketches came she admired 'em so that I began to hate you
then. Yes, Mr. Sidney, you was a relative, and goin' to be a success,
and the look in her eyes when she saw your work killed me. It killed
me!
Do, do get up, said Philip, trying to raise her. Don't weep so, Eliza.
I understand.
But the torrent could not yet be stemmed.
I've looked forward to your comin' like to an operation. I've thought
you might laugh at her pictures, 'cause young folks are so cruel, and
they don't know! Let me cry, Mr. Sidney. Don't mind! You've given
me the first happy moment I've known since she left me. I was the
only one she had, even to go to picture galleries with her, and my
bones ached 'cause I was a stupid thing, and she had wings just like
a little spirit o' light.
Philip's lashes were moist again.
I wish I had been here to go with her, he said.
Eliza lifted her streaming eyes. Would you 'a' gone? she asked, and
allowed Phil to raise her gently to her feet.
Indeed, I would, he answered gravely, and we should have lived
together, and worked together.
Oh, why couldn't it 'a' been! Why couldn't it 'a' been! What it would
'a' meant to her to have heard what you said just now about her
pictures!
Phil's hands were holding Eliza's thin shoulders, and her famished
eyes were drinking in the comfort of him.
I have an idea that we ought not to believe that we could make her
happier than she is, he said, with the same gravity.
I know, faltered Eliza, surprised; of course that's the way I ought
to feel; but there wasn't ever anything she cared much about except
paintin'. She—Eliza swallowed the tremulous sob that was the
aftermath of the storm—she loved music, but she wasn't a
performer.
Phil smiled into the appealing face.
Then she's painting, for all we know, he said. Do you believe
music is all that goes on there?
It's all that's mentioned, said Eliza apologetically.
I have an idea that dying doesn't change us any, said the young
man. Why should it?
It didn't need to change her, agreed the other, her voice breaking.
I believe that in the end we get what we want.
That's comfortin'.
Not so you'd notice it, returned Phil with conviction. It makes the
chills run down my spine occasionally when I stop to realize it.
What do you mean?
Only that we had better examine what we're wanting; and choose
something that won't go back on us. Aunt Mary did; and I believe
she had a strong faith.
We never talked religion, said Eliza.
Just lived it. That's better.
I didn't, returned Eliza, a spark of the old belligerency flashing in
her faded eyes. I can't think of one single enemy that I love!
You were everything to Aunt Mary. Do you suppose I shall ever
forget that?
I sat down in front o' those pictures in the Metropolitan Museum,
said Eliza, her lips trembling again. It's awful big, and I got so
tuckered, the pictures sort o' ran together till I didn't know a
landscape from a portrait. Then I used to take on over somethin'
that had a seat in front of it, and she'd leave me sittin' there starin'.
Oh, Mr. Sidney, I can't think o' one other mean thing I ever did to
her,—remorseful grief shook the speaker's voice,—but I'd ought to
'a' stood up to the end. It would 'a' showed more interest!
Phil squeezed the spare shoulders as they heaved. He laughed a
little.
Now, Eliza, whatever way you managed it, I know you made her
happy.
Yes, groaned the repentant one, she said my artistic soul was
wakin' up. Do you s'pose where she is now she knows it was black
deceit?
She knows nothing black where she is,—Phil's voice rang with
decision; but she does know more than ever about love and
sacrifice such as you have shown her. Beside, in a lighter tone,
how about your artistic soul? See how far above everybody else you
understood her pictures.
Eliza's hungry gaze became suddenly inscrutable. Mr. Sidney, she
began, after a pause, I loved every stroke her dear hand made,
but—again pain crept into the breaking voice—you said yourself
America wasn't worthy of her, and I'm only what you might call the
scum of America when it comes to insight and—and expression and
—and atmosphere. Usually I had sense enough to wait till she told
me what a thing was before I talked about it; but one day, I can't
ever forget it, I praised a flock o' sheep at the back of a field she
was doin' and she said they was—was cows!
Sobs rent the speaker and she covered her eyes.
I told her—'twas my glasses, she went on when she could speak.
I—told her they—hadn't been right for—a long time. She laughed—
and tried to make a joke of it, but—
Eliza's voice was drowned in the flood.
Phil patted her shoulders and smiled across the bowed head at the
forlorn mantelpiece, where the sketches, unconscious of forgiveness,
still turned faces toward the wall.
You've grown awfully morbid, alone here, he said, giving her a
little shake. You should be only thankful, as I am, that Aunt Mary
had you and that you were here to take care of her to the end.
Come and sit down. She wrote me a wonderful letter. I have it in my
pocket and I'll show it to you.
Eliza obediently yielded herself to be guided to a chair. Pluto had
selected the best with unerring instinct; and suddenly into his feline
dreams an earthquake intruded as Phil tossed him lightly to the floor.
Drawing his chair close to Eliza, who had wilted back against the
faded cretonne roses, the young man drew from his pocket an
envelope and took out of it a letter, and a small card photograph.
Mother gave me this old picture of Aunt Mary—
Eliza pulled herself up and took it eagerly. I must get my glasses,
she said. I've cried myself nearly blind.
Phil's big hand pushed her back.
I'll get them, he returned. Where are they?
There, on the end o' the mantelpiece. I had 'em, readin' an
advertisement.
She leaned back again and watched him as he crossed the room;
watched him with wonder. In years she had not so given her
confidence to a human being.
She put on the spectacles and wistfully regarded the picture of a
pretty woman whose heavy braids, wound around her head, caught
the light. Her plain dress was white and she wore black velvet bands
on her wrists.
Aunt Mary was considered different by her friends, mother says. In
a time of frills she liked plain things.
I guess she was different, agreed Eliza devoutly. Would you think
a man who married her would like whiskey better?
Phil shook his head. Sorry, he said, laconically.
One good thing, he drank himself to death quick and left her free.
Phil held out the letter.
Read it to me, please, Mr. Sidney.
Can't do it, returned the young man with cheerful frankness. It
makes my nose tingle every time.
So Eliza read the letter in silence. It took her some minutes and
when she had finished, her lip caught between her teeth, she took
off her glasses and wiped them while she regarded Phil.
And you've got to live up to that, she said.
I'm going to try, he answered simply.
Eliza gazed at him, her hands in her lap. She felt old beside his
youth, weak beside his strength, ignorant beside that knowledge
which had stirred her mistress to exaltation. Nevertheless, the
humble love, and desire to help him that swelled her heart was a
new desire to live, a consecration.
Presently he took his leave, promising to return in a few days for his
belongings.
After the door had closed behind him, she looked down at the cat,
who had awakened from another nap at the stir of the departure.
He rubbed against her brown calico skirt as she lighted the gas; then
she moved thoughtfully to the mantelpiece and turned the sketches
about.
Mary Sidney, she mused, looking at the graceful head of Phil's
mother, you've had your heartache, and your sacrifices. You've been
most pulled in two, between longin' to stay with your husband and
follow your son—you told me somethin' of it in your note thankin' for
the brooch. Nobody escapes, Mary Sidney. I guess I haven't done
you justice, seein' you've raised a boy like that.
Turning to the sketch of the storm-beaten tree, she clasped her
hands before it. Dear one, she mused tenderly, you loved him.
You was great. You died not knowin' how great you were; and you
won't care if I do understand this kind better, 'cause all America's too
ignorant for you, and I'm one o' the worst.
Her eyes dwelt lingeringly on the sketch. She fancied she could hear
the wind whistling through the writhing branches. It looks like my
life, she thought, risin' out o' the mist and the cloud.
She gazed at it in silence, then turned to the destroyed photograph.
She seized the pieces quickly and turned them face up. The rent had
missed the chin and cut across the collar. She regarded the face
wistfully. The cat stretched his forepaws up her skirt until he was of
a preternatural length. It was supper-time.
I wonder, Pluto, she said slowly, if I couldn't fit that into a
minicher frame. Some of 'em come real reasonable.
CHAPTER V
ELIZA'S INVITATION
For the first time since she had been left alone, Eliza drank her tea
that night without tears; and no lump in her throat prevented her
swallowing the egg she had boiled.
She held Mrs. Ballard's watch in her hand a minute before getting
into bed; and looked long at its gold face, and listened to its loud
and busy ticking.
Forgive me, Mrs. Ballard, she thought; and association added, as
we forgive our debtors!
No, I can't! she muttered fiercely. I can't! What's the use o'
pretendin'!
Muffling the watch in its slipper, she turned out the gas and got into
bed. Composing herself to sleep more peacefully than she had been
able to do for many a night, her last thought was of Mrs. Ballard's
heir; and a sense of comfort stole over her in the very fact of his
existence. Again she seemed to feel the sympathetic pressure of his
kind hand.
He thinks she may be paintin' still, she reflected. She's got colors
to work with that's most blindin', they're so gorgeous, if we can
judge anything by the sunsets at the island. Why not think so! It's
just as reasonable as playin' harps, for all I can see.
Ever since her dear one's passing, Eliza had felt too crushed and too
wicked to pray; and being unable to say the whole of her Lord's
Prayer, her New England conscience would not allow her to say any
of it; but to-night a sense of hope and gratitude lightened the
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
Let us accompany you on the journey of exploring knowledge and
personal growth!
textbookfull.com

More Related Content

PDF
Get Object Oriented Data Structures Using Java 4th Edition Dale free all chap...
zeniraadjou
 
PDF
(eBook PDF) Data Structures and Other Objects Using Java 4th Edition
adweguggu
 
PPT
Chap01
Jotham Gadot
 
PDF
Java Foundations Introduction to Program Design and Data Structures (5th Edit...
hariomtapang
 
PDF
Class notes(week 2) on basic concepts of oop-2
Kuntal Bhowmick
 
DOCX
Class notes(week 2) on basic concepts of oop-2
Kuntal Bhowmick
 
PDF
Data Structures and Abstractions with Java 5th Edition Carrano Solutions Manual
AvaRosalessa
 
PDF
Java Programming.pdf
IthagoniShirisha
 
Get Object Oriented Data Structures Using Java 4th Edition Dale free all chap...
zeniraadjou
 
(eBook PDF) Data Structures and Other Objects Using Java 4th Edition
adweguggu
 
Chap01
Jotham Gadot
 
Java Foundations Introduction to Program Design and Data Structures (5th Edit...
hariomtapang
 
Class notes(week 2) on basic concepts of oop-2
Kuntal Bhowmick
 
Class notes(week 2) on basic concepts of oop-2
Kuntal Bhowmick
 
Data Structures and Abstractions with Java 5th Edition Carrano Solutions Manual
AvaRosalessa
 
Java Programming.pdf
IthagoniShirisha
 

Similar to Object Oriented Data Structures Using Java 4th Edition Dale (20)

PDF
Java Software Structures Designing And Using Data Structures 3rd Edition John...
phemilohana
 
PDF
Data structure & algorithm using java
Narayan Sau
 
PPTX
automatic dol starter
BANDARISANDEEP
 
PDF
M.c.a. (sem iv)- java programming
Praveen Chowdary
 
DOC
Programming paradigms
AVC College of Engineering
 
PDF
MCA NOTES.pdf
RAJASEKHARV10
 
DOCX
Unit1 jaava
mrecedu
 
PPT
1-Lec - Introduction vhvv,vbvv,v (2).ppt
AqeelAbbas94
 
PDF
Java Foundations Introduction To Program Design And Data Structures 2nd Editi...
eestissingar
 
PDF
Java Java Java Objectoriented Problem Solving 3rd Edition Ralph Morelli Ralph...
maunusmdou
 
PPT
java
jent46
 
PPT
Java is an Object-Oriented Language
ale8819
 
PDF
1.Java_programming2017.pdf
MohamedTarekAbdelsal
 
PDF
C Plus Data Structures Subsequent Dale Nell B
noyzdapat39
 
PPTX
JAVA PROGRAMMINGD
Niyitegekabilly
 
PDF
Data structures and_algorithms_in_java
Prabhu vip
 
PPTX
Birasa 1
Niyitegekabilly
 
PPTX
JAVA PROGRAMMING
Niyitegekabilly
 
KEY
Objects & OO Thinking for Java
Jeff Sonstein
 
PPTX
Journey-into-the-World-of-Java.pp3dqe23R3qtx
jaynanad14
 
Java Software Structures Designing And Using Data Structures 3rd Edition John...
phemilohana
 
Data structure & algorithm using java
Narayan Sau
 
automatic dol starter
BANDARISANDEEP
 
M.c.a. (sem iv)- java programming
Praveen Chowdary
 
Programming paradigms
AVC College of Engineering
 
MCA NOTES.pdf
RAJASEKHARV10
 
Unit1 jaava
mrecedu
 
1-Lec - Introduction vhvv,vbvv,v (2).ppt
AqeelAbbas94
 
Java Foundations Introduction To Program Design And Data Structures 2nd Editi...
eestissingar
 
Java Java Java Objectoriented Problem Solving 3rd Edition Ralph Morelli Ralph...
maunusmdou
 
java
jent46
 
Java is an Object-Oriented Language
ale8819
 
1.Java_programming2017.pdf
MohamedTarekAbdelsal
 
C Plus Data Structures Subsequent Dale Nell B
noyzdapat39
 
JAVA PROGRAMMINGD
Niyitegekabilly
 
Data structures and_algorithms_in_java
Prabhu vip
 
Birasa 1
Niyitegekabilly
 
JAVA PROGRAMMING
Niyitegekabilly
 
Objects & OO Thinking for Java
Jeff Sonstein
 
Journey-into-the-World-of-Java.pp3dqe23R3qtx
jaynanad14
 
Ad

Recently uploaded (20)

PDF
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
PDF
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
PDF
Sunset Boulevard Student Revision Booklet
jpinnuck
 
PDF
Virat Kohli- the Pride of Indian cricket
kushpar147
 
PDF
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
PPTX
Artificial-Intelligence-in-Drug-Discovery by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
Celine George
 
PPTX
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
PPTX
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
PDF
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
PDF
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
PPTX
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
PDF
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
PPTX
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
PDF
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PDF
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
PPTX
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
PPTX
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
PPTX
PREVENTIVE PEDIATRIC. pptx
AneetaSharma15
 
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
Sunset Boulevard Student Revision Booklet
jpinnuck
 
Virat Kohli- the Pride of Indian cricket
kushpar147
 
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
Artificial-Intelligence-in-Drug-Discovery by R D Jawarkar.pptx
Rahul Jawarkar
 
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
Celine George
 
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
PREVENTIVE PEDIATRIC. pptx
AneetaSharma15
 
Ad

Object Oriented Data Structures Using Java 4th Edition Dale

  • 1. Explore the full ebook collection and download it now at textbookfull.com Object Oriented Data Structures Using Java 4th Edition Dale https://textbookfull.com/product/object-oriented-data- structures-using-java-4th-edition-dale/ OR CLICK HERE DOWLOAD EBOOK Browse and Get More Ebook Downloads Instantly at https://textbookfull.com Click here to visit textbookfull.com and download textbook now
  • 2. Your digital treasures (PDF, ePub, MOBI) await Download instantly and pick your perfect format... Read anywhere, anytime, on any device! Object Orientation Abstraction and Data Structures Using Scala Second Edition Lacher https://textbookfull.com/product/object-orientation-abstraction-and- data-structures-using-scala-second-edition-lacher/ textbookfull.com A Functional Approach to Java: Augmenting Object-Oriented Java Code with Functional Principles 1st Edition Ben Weidig https://textbookfull.com/product/a-functional-approach-to-java- augmenting-object-oriented-java-code-with-functional-principles-1st- edition-ben-weidig/ textbookfull.com Practical object-oriented design: an agile primer using Ruby Second Edition Metz https://textbookfull.com/product/practical-object-oriented-design-an- agile-primer-using-ruby-second-edition-metz/ textbookfull.com Swift 3 Object Oriented Programming Gaston C. Hillar https://textbookfull.com/product/swift-3-object-oriented-programming- gaston-c-hillar/ textbookfull.com
  • 3. Introduction to Java Programming and Data Structures Comprehensive Version Y Daniel Liang https://textbookfull.com/product/introduction-to-java-programming-and- data-structures-comprehensive-version-y-daniel-liang/ textbookfull.com Problem Solving in Data Structures & Algorithms Using C First Edition Jain https://textbookfull.com/product/problem-solving-in-data-structures- algorithms-using-c-first-edition-jain/ textbookfull.com Programming In C Object Oriented Features 1st Edition Laxmisha Rai https://textbookfull.com/product/programming-in-c-object-oriented- features-1st-edition-laxmisha-rai/ textbookfull.com Advanced Object-Oriented Programming in R: Statistical Programming for Data Science, Analysis and Finance 1st Edition Thomas Mailund https://textbookfull.com/product/advanced-object-oriented-programming- in-r-statistical-programming-for-data-science-analysis-and- finance-1st-edition-thomas-mailund/ textbookfull.com Think Data Structures: Algorithms and Information Retrieval in Java 1st Edition Allen B. Downey https://textbookfull.com/product/think-data-structures-algorithms-and- information-retrieval-in-java-1st-edition-allen-b-downey/ textbookfull.com
  • 6. Java™ Fourth Edition Nell Dale University of Texas, Austin Daniel T. Joyce Villanova University Chip Weems University of Massachusetts, Amherst Java using Object-Oriented Data Structures
  • 7. World Headquarters Jones & Bartlett Learning 5 Wall Street Burlington, MA 01803 978-443-5000 [email protected] www.jblearning.com Jones & Bartlett Learning books and products are available through most bookstores and online booksellers. To contact Jones & Bartlett Learning directly, call 800-832-0034, fax 978-443-8000, or visit our website, www.jblearning.com. Substantial discounts on bulk quantities of Jones & Bartlett Learning publications are available to corporations, professional associa- tions, and other qualified organizations. For details and specific discount information, contact the special sales department at Jones & Bartlett Learning via the above contact information or send an email to [email protected]. Copyright © 2018 by Jones & Bartlett Learning, LLC, an Ascend Learning Company All rights reserved. No part of the material protected by this copyright may be reproduced or utilized in any form, electronic or mechani- cal, including photocopying, recording, or by any information storage and retrieval system, without written permission from the copyright owner. The content, statements, views, and opinions herein are the sole expression of the respective authors and not that of Jones & Bartlett Learn- ing, LLC. Reference herein to any specific commercial product, process, or service by trade name, trademark, manufacturer, or otherwise does not constitute or imply its endorsement or recommendation by Jones & Bartlett Learning, LLC and such reference shall not be used for advertising or product endorsement purposes. All trademarks displayed are the trademarks of the parties noted herein. Object-Oriented Data Structures Using Java, Fourth Edition is an independent publication and has not been authorized, sponsored, or otherwise approved by the owners of the trademarks or service marks referenced in this product. 09820-4 Production Credits VP, Executive Publisher: David D. Cella Acquisitions Editor: Laura Pagluica Editorial Assistant: Taylor Ferracane Director of Vendor Management: Amy Rose Marketing Manager: Amy Langlais VP, Manufacturing and Inventory Control: Therese Connell Composition and Project Management: S4Carlisle Publishing Services Cover Design: Kristin E. Parker Text Design: Scott Moden Rights & Media Specialist: Merideth Tumasz Media Development Editor: Shannon Sheehan Cover Image: © Ake13bk/Shutterstock Printing and Binding: Edwards Brothers Malloy Cover Printing: Edwards Brothers Malloy Library of Congress Cataloging-in-Publication Data Names: Dale, Nell (Nell B.), author. | Joyce, Daniel T., author. | Weems, Chip., author. Title: Object-oriented data structures using Java / Nell Dale, Daniel T. Joyce, Chip Weems. Description: Fourth edition. | Burlington, MA : Jones & Bartlett Learning, [2017] Identifiers: LCCN 2016025145 | ISBN 9781284089097 (casebound) Subjects: LCSH: Object-oriented programming (Computer science) | Data structures (Computer science) | Java (Computer program language) Classification: LCC QA76.64 .D35 2017 | DDC 005.13/3--dc23 LC record available at https://lccn.loc.gov/2016025145 6048 Printed in the United States of America 20 19 18 17 16 10 9 8 7 6 5 4 3 2 1
  • 8. To Alfred G. Dale ND To Kathy, Tom, and Julie, thanks for the love and support DJ To Lisa, Charlie, and Abby, thank you . . . CW
  • 9. © Ake13bk/Shutterstock Welcome to the fourth edition of Object-Oriented Data Structures Using Java™. This book pres- ents the algorithmic, programming, and structuring techniques of a traditional data structures course in an object-oriented context. You’ll find the familiar topics of linked lists, recursion, stacks, queues, collections, indexed lists, trees, maps, priority queues, graphs, sorting, searching, and complexity analysis, all covered from an object-oriented point of view using Java. We stress software engineering principles throughout, including modularization, information hiding, data abstraction, stepwise refinement, the use of visual aids, the analysis of algorithms, and software verification methods. To the Student You know that an algorithm is a sequence of unambiguous instructions for solving a problem. You can take a problem of moderate complexity, design a small set of classes/objects that work together to solve the problem, code the method algorithms needed to make the objects work, and demonstrate the correctness of your solution. Algorithms describe actions. These actions manipulate data. For most interesting problems that are solved using computers, the structure of the data is just as important as the structure of the algorithms used to manipulate the data. Using this text you will discover that the way you structure data affects how efficiently you can use the data; you will see how the nature of the problem you are attempting to solve dictates your structuring decisions; and you will learn about the data structures that computer scientists have developed over the years to help solve problems. Object-Oriented Programming with Java Our primary goal is to present both the traditional and modern data structure topics with an emphasis on problem solving and software design. Using the Java programming language as a vehicle for problem solutions, however, presents an opportunity for students to expand their Preface
  • 10. Preface v familiarity with a modern programming language and the object-oriented paradigm. As our data structure coverage unfolds, we introduce and use the appropriate Java constructs that support our primary goal. Starting early and continuing throughout the text, we introduce and expand on the use of many Java features such as classes, objects, generics, polymorphism, packages, interfaces, library classes, inheritance, exceptions, and threads. We also use Universal Modeling Language (UML) class diagrams throughout to help model and visualize our objects, classes, interfaces, applications, and their interrelationships. Features Data Abstraction In this text we view our data structures from three different perspectives: their specification, their application, and their implementation. The specification describes the logical or abstract level—what the logical relationships among the data elements are and what operations can be performed on the structure. The application level, sometimes called the client level, is concerned with how the data structure is used to solve a problem—why the operations do what they do. The implementation level involves the coding details—how the structures and operations are implemented. In other words we treat our data structures as abstract data types (ADTs). Efficiency Analysis In Chapter 1 we introduce order of growth efficiency analysis using a unique approach involving the interaction of two students playing a game. Time and space analysis is consistently applied throughout the text, allowing us to compare and contrast data structure implementations and the applications that use them. Recursion Treatment Recursion is introduced early (Chapter 3) and used throughout the re- mainder of the text. We present a design and analysis approach to recursion based on answering three simple questions. Answering the questions, which are based on formal inductive reasoning, leads the programmer to a solid recursive design and program. Interesting Applications Eight primary data structures (stacks, queues, collections, indexed lists, trees, maps, priority queues, and graphs) are treated in separate chapters that include their definition, several implementations, and one or more interesting applications based on their use. Applications involve, for example, balanced expressions, postfix expressions, image generation (new!), fractals (new!), queue simulation, card decks and games (new!), text analysis (new!), tree and graph traversals, and big integers. Robust Exercises We average more than 40 exercises per chapter. The exercises are organized by chapter sections to make them easier for you to manage. They vary in level of difficulty, including short and long programming problems (marked with “programming-required” icons—one icon to indicate short exercises and two icons for projects), the analysis of algorithms, and problems to test students’ understanding of abstract concepts. In this edition we have streamlined the previous exercises, allowing us to add even more options for you to choose from. In particular we have added several larger programming exercises to many of the chapters. Input/Output Options It is difficult to know what background the students using a data struc- tures text will have in Java I/O. To allow all the students using our text to concentrate on the
  • 11. vi Preface primary topic of data structures, we use the simplest I/O approach we can, namely a command line interface. However, to support those teachers and students who prefer to work with graphi- cal user interfaces (GUIs), we provide GUIs for many of our applications. Our modular approach to program design supports this approach—our applications separate the user interface code, problem solution code, and ADT implementation code into separate classes. Concurrency Coverage We are pleased to be one of the only data structures texts to address the topics of concurrency and synchronization, which are growing in importance as computer systems move to using more cores and threads to obtain additional performance with each new generation. We introduce this topic in Section 4.9, “Concurrency, Interference, and Synchronization,” where we start with the basics of Java threads, continue through examples of thread interference and synchronization, and culminate in a discussion of efficiency concerns. New to the Fourth Edition This edition represents a major revision of the text’s material, although the philosophy and style that our loyal adopters have grown to appreciate remain unchanged. We removed material we felt was redundant or of lesser/outdated importance to the core topic of data structures, added new key material, and reworked much of the material that we kept. Although the length of the textbook was reduced by about 10%, the coverage of data structures has been expanded. We believe this new edition is a great improvement over previous editions and hope you do, too. Major changes include: • Simplified Architecture: We continue to use the Java interface construct to define the abstract view of our ADTs, but we have reduced the number of levels of inheritance, simplifying the architecture and making it easier to understand and use. • New Chapters: Chapter 5, “The Collection ADT,” and Chapter 8, “The Map ADT,” are brand new. The Collection ADT material introduces the idea of a data structure as a repository and concentrates on storage and retrieval of data based on key attri- butes. The Map ADT has become increasingly important with the rise in popularity of scripting languages with built-in associative arrays. • New Section: Section 1.6, “Comparing Algorithms: Order of Growth Analysis,” was completely rewritten and features an introduction to efficiency analysis driven by a game played between two students, plus analysis of sequential search, binary search, and sequential sort algorithms. • New Sections: In response to reader’s suggestions, Chapter 3, “Recursion,” features two new sections: Section 3.3, “Recursive Processing of Arrays,” is devoted to recur- sive processing of arrays and Section 3.4, “Recursive Processing of Linked Lists,” is devoted to recursive processing of linked lists. These new sections provide practical examples of the use of recursion, before the reader moves on to the less practical but nevertheless popular Towers of Hanoi example covered in Section 3.5, “Towers.” • New Section: Fractals! A fun section related to recursively generating fractal-based images now wraps up the examples of Chapter 3, “Recursion.”
  • 12. Preface vii • New Sections: We added “Variations” sections to the Stack, Queue, Collection, List, Tree, and Map chapters. In the primary exposition of each of these ADTs we record design decisions and specify the operations to be supported by the ADT. We also develop or at least discuss various implementation approaches, in most cases high- lighting one array-based approach and one reference/linked-list-based approach. The “Variations” section discusses alternate approaches to defining/implementing the ADT and in most cases reviews the ADT counterparts available in the standard Java Library. Some of these sections also introduce related ADTs, for example, in the “Variations” section of the Collection chapter we define and discuss both the Set and Bag ADTs. • Glossary: The text’s glossary has always been available online. With this edition we make it available as Appendix E. Throughout the text we highlight important terms that might be unfamiliar to the student in green, the first time they are featured, to indicate that their definition can be found in the glossary. Prerequisite Assumptions In this book, we assume that readers are familiar with the following Java constructs: • Built-in simple data types and the array type • Control structures while, do, for, if, and switch • Creating and instantiating objects • Basic user-defined classes: ■ variables and methods ■ constructors, method parameters, and the return statement ■ visibility modifiers • Commonly used Java Library Classes: Integer, Math, Random, Scanner, String, and System Chapter Content Chapter 1 is all about Getting Organized. An overview of object orientation stresses mecha- nisms for organizing objects and classes. The Java exception handling mechanisms, used to organize response to unusual situations, are introduced. Data structures are previewed and the two fundamental language constructs that are used to implement those structures, the array and the reference (link/pointer), are discussed. The chapter concludes with a look at efficiency analysis—how we evaluate and compare algorithms. Chapter 2 presents The Stack ADT. The concept of abstract data type (ADT) is introduced. The stack is viewed from three different levels: the abstract, application, and implementation levels. The Java interface mechanism is used to support this three-tiered view. We also investigate using generics to support generally usable ADTs. The Stack ADT is implemented using both arrays and references. To support the reference-based approach we introduce the linked list structure. Sample applications include determining if a set of grouping symbols is well formed and the evaluation of postfix expressions.
  • 13. viii Preface Chapter 3 discusses Recursion, showing how recursion can be used to solve programming problems. A simple three-question technique is introduced for verifying the correctness of re- cursive methods. Sample applications include array processing, linked list processing, the classic Towers of Hanoi, and fractal generation. A detailed discussion of how recursion works shows how recursion can be replaced with iteration and stacks. Chapter 4 presents The Queue ADT. It is also first considered from its abstract perspective, followed by a formal specification, and then implemented using both array-based and reference- based approaches. Example applications include an interactive test driver, a palindrome checker, and simulating a system of real-world queues. Finally, we look at Java’s concurrency and synchro- nization mechanisms, explaining issues of interference and efficiency. Chapter 5 defines The Collection ADT. A fundamental ADT, the Collection, supports storing information and then retrieving it later based on its content. Approaches for comparing objects for equality and order are reviewed. Collection implementations using an array, a sorted array, and a linked list are developed. A text processing application permits comparison of the imple- mentation approaches for efficiency. The “Variations” section introduces two more well-known ADTs: the Bag and the Set. Chapter 6 follows up with a more specific Collection ADT, The List ADT. In fact, the following two chapters also develop Collection ADTs. Iteration is introduced here and the use of anonymous inner classes to provide iterators is presented. As with the Collection ADT we develop array, sorted array, and linked-list–based implementations. The “Variations” section includes an example of how to “implement” a linked list within an array. Applications include a card deck model plus some card games, and a Big Integer class. This latter application demonstrates how we sometimes design specialized ADTs for specific problems. Chapter 7 develops The Binary Search Tree ADT. It requires most of the chapter just to design and create our reference-based implementation of this relatively complex structure. The chapter also discusses trees in general (including breadth-first and depth-first searching) and the problem of balancing a binary search tree. A wide variety of special-purpose and self-balancing trees are introduced in the “Variations” section. Chapter 8 presents The Map ADT, also known as a symbol table, dictionary, or associative array. Two implementations are developed, one that uses an ArrayList and the other that uses a hash table. A large part of the chapter is devoted to this latter implementation and the important concept of hashing, which provides a very efficient implementation of a Map. The “Variations” section discusses a map-based hybrid data structure plus Java’s support for hashing. Chapter 9 introduces The Priority Queue ADT, which is closely related to the Queue but with a different accessing protocol. This short chapter does present a sorted array-based implementa- tion, but most of the chapter focuses on a clever, interesting, and very efficient implementation called a Heap. Chapter 10 covers The Graph ADT, including implementation approaches and several important graph-related algorithms (depth-first search, breadth-first search, path existence, shortest paths, and connected components). The graph algorithms make use of stacks, queues, and priority queues, thus both reinforcing earlier material and demonstrating the general us- ability of these structures.
  • 14. Preface ix Chapter 11 presents/reviews a number of Sorting and Searching Algorithms. The sorting algorithms that are illustrated, implemented, and compared include straight selection sort, two versions of bubble sort, insertion sort, quick sort, heap sort, and merge sort. The sorting algo- rithms are compared using efficiency analysis. The discussion of algorithm analysis continues in the context of searching. Previously presented searching algorithms are reviewed and new ones are described. Organization Chapter Goals Sets of knowledge and skill goals are presented at the beginning of each chapter to help the students assess what they have learned. Sample Programs Numerous sample programs and program segments illustrate the abstract concepts throughout the text. Feature Sections Throughout the text these short sections highlight topics that are not directly part of the flow of material but nevertheless are related and important. Boxed Notes These small boxes of information scattered throughout the text highlight, supple- ment, and reinforce the text material, perhaps from a slightly different point of view. Chapter Summaries Each chapter concludes with a summary section that reviews the most im- portant topics of the chapter and ties together related topics. Some chapter summaries include a UML diagram of the major interfaces and classes developed within the chapter. Appendices The appendices summarize the Java reserved word set, operator precedence, primitive data types, the ASCII subset of Unicode, and provide a glossary of important terms used in the text. Website http://go.jblearning.com/oods4e This website provides access to the text’s source code files for each chapter. Additionally, regis- tered instructors are able to access selected answers to the text’s exercises, a test item file, and presentation slides. Please contact the authors if you have material related to the text that you would like to share with others.
  • 15. x Preface Acknowledgments We would like to thank the following people who took the time to review this text: Mark Llewellyn at the University of Central Florida, Chenglie Hu at Carroll College, Val Tannen at the University of Pennsylvania, Chris Dovolis at the University of Minnesota, Mike Coe at Plano Senior High School, Mikel Petty at University of Alabama in Huntsville, Gene Sheppard at Georgia Perimeter College, Noni Bohonak at the University of South Carolina–Lancaster, Jose Cordova at the University of Louisiana–Monroe, Judy Gurka at the Metropolitan State College of Denver, Mikhail Brikman at Salem State University, Amitava Karmaker at University of Wisconsin–Stout, Guifeng Shao at Tennessee State University, Urska Cvek at Louisiana State University at Shreveport, Philip C. Doughty Jr. at Northern Virginia Community College, Jeff Kimball at Southwest Baptist University, Jeremy T. Lanman at Nova Southeastern University, Rao Li at University of South Carolina Aiken, Larry Thomas at University of Toledo, and Karen Works at Westfield State University. A special thanks to Christine Shannon at Centre College, to Phil LaMastra at Fairfield University, to Allan Gottlieb of New York University, and to J. William Cupp at Indiana Wesleyan University for specific comments leading to improvements in the text. A personal thanks to Kristen Obermyer, Tara Srihara, Sean Wilson, Christopher Lezny, and Naga Lakshmi, all of Villanova University, plus Kathy, Tom, and Julie Joyce for all of their help, support, and proofreading expertise. A virtual bouquet of roses to the editorial and production teams who contributed so much, especially Laura Pagluica, Taylor Ferracane, Amy Rose, and Palaniappan Meyyappan. ND DJ CW
  • 16. © Ake13bk/Shutterstock 1 Getting Organized 1 1.1 Classes, Objects, and Applications 2 Classes 2 The Unified Method 7 Objects 8 Applications 10 1.2 Organizing Classes 12 Inheritance 12 Packages 19 1.3 Exceptional Situations 22 Handling Exceptional Situations 22 Exceptions and Classes: An Example 23 1.4 Data Structures 27 Implementation-Dependent Structures 28 Implementation-Independent Structures 29 What Is a Data Structure? 31 1.5 Basic Structuring Mechanisms 32 Memory 32 References 34 Arrays 38 1.6 Comparing Algorithms: Order of Growth Analysis 43 Measuring an Algorithm’s Time Efficiency 44 Complexity Cases 45 Size of Input 46 Comparing Algorithms 47 Order of Growth 49 Contents
  • 17. xii Contents Selection Sort 50 Common Orders of Growth 53 Summary 54 Exercises 55 2 The Stack ADT 67 2.1 Abstraction 68 Information Hiding 68 Data Abstraction 69 Data Levels 70 Preconditions and Postconditions 71 Java Interfaces 72 Interface-Based Polymorphism 76 2.2 The Stack 78 Operations on Stacks 79 Using Stacks 79 2.3 Collection Elements 81 Generally Usable Collections 81 2.4 The Stack Interface 84 Exceptional Situations 85 The Interface 88 Example Use 89 2.5 Array-Based Stack Implementations 90 The ArrayBoundedStack Class 91 Definitions of Stack Operations 93 The ArrayListStack Class 99 2.6 Application: Balanced Expressions 101 The Balanced Class 102 The Application 107 The Software Architecture 111 2.7 Introduction to Linked Lists 111 Arrays Versus Linked Lists 111 The LLNode Class 113 Operations on Linked Lists 115 2.8 A Link-Based Stack 121 The LinkedStack Class 122 The push Operation 124 The pop Operation 127 The Other Stack Operations 129 Comparing Stack Implementations 131 2.9 Application: Postfix Expression Evaluator 132 Discussion 132 Evaluating Postfix Expressions 133
  • 18. Contents xiii Postfix Expression Evaluation Algorithm 134 Error Processing 136 The PostFixEvaluator Class 137 The PFixCLI Class 139 2.10 Stack Variations 142 Revisiting Our Stack ADT 142 The Java Stack Class and the Collections Framework 143 Summary 145 Exercises 147 3 Recursion 161 3.1 Recursive Definitions, Algorithms, and Programs 162 Recursive Definitions 162 Recursive Algorithms 163 Recursive Programs 166 Iterative Solution for Factorial 167 3.2 The Three Questions 167 Verifying Recursive Algorithms 168 Determining Input Constraints 169 Writing Recursive Methods 169 Debugging Recursive Methods 170 3.3 Recursive Processing of Arrays 170 Binary Search 170 3.4 Recursive Processing of Linked Lists 174 Recursive Nature of Linked Lists 175 Traversing a Linked List 175 Transforming a Linked List 178 3.5 Towers 182 The Algorithm 182 The Method 184 The Program 186 3.6 Fractals 186 A T-Square Fractal 187 Variations 190 3.7 Removing Recursion 191 How Recursion Works 191 Tail Call Elimination 195 Direct Use of a Stack 196 3.8 When to Use a Recursive Solution 197 Recursion Overhead 198 Inefficient Algorithms 198 Clarity 200
  • 19. xiv Contents Summary 202 Exercises 202 4 The Queue ADT 217 4.1 The Queue 218 Operations on Queues 219 Using Queues 219 4.2 The Queue Interface 220 Example Use 222 4.3 Array-Based Queue Implementations 223 The ArrayBoundedQueue Class 223 The ArrayUnboundedQueue Class 230 4.4 An Interactive Test Driver 234 The General Approach 234 A Test Driver for the ArrayBoundedQueue Class 235 Using the Test Driver 235 4.5 Link-Based Queue Implementations 237 The Enqueue Operation 238 The Dequeue Operation 239 A Circular Linked Queue Design 241 Comparing Queue Implementations 242 4.6 Application: Palindromes 244 The Palindrome Class 244 The Applications 246 4.7 Queue Variations 248 Exceptional Situations 248 The GlassQueue 248 The Double-Ended Queue 251 Doubly Linked Lists 252 The Java Library Collection Framework Queue/Deque 255 4.8 Application: Average Waiting Time 257 Problem Discussion and Example 258 The Customer Class 259 The Simulation 262 Testing Considerations 268 4.9 Concurrency, Interference, and Synchronization 268 The Counter Class 270 Java Threads 271 Interference 274 Synchronization 275 A Synchronized Queue 277 Concurrency and the Java Library Collection Classes 282
  • 20. Contents xv Summary 283 Exercises 284 5 The Collection ADT 297 5.1 The Collection Interface 298 Assumptions for Our Collections 299 The Interface 299 5.2 Array-Based Collection Implementation 301 5.3 Application: Vocabulary Density 305 5.4 Comparing Objects Revisited 308 The equals Method 308 The Comparable Interface 314 5.5 Sorted Array-Based Collection Implementation 315 Comparable Elements 316 The Implementation 317 Implementing ADTs “by Copy” or “by Reference” 319 Sample Application 323 5.6 Link-Based Collection Implementation 325 The Internal Representation 325 The Operations 326 Comparing Collection Implementations 329 5.7 Collection Variations 330 The Java Collections Framework 330 The Bag ADT 331 The Set ADT 333 Summary 336 Exercises 337 6 The List ADT 345 6.1 The List Interface 346 Iteration 346 Assumptions for Our Lists 348 The Interface 348 6.2 List Implementations 350 Array-Based Implementation 350 Link-Based Implementation 355 6.3 Applications: Card Deck and Games 361 The Card Class 361 The CardDeck Class 363 Application: Arranging a Card Hand 366 Application: Higher or Lower? 369 Application: How Rare Is a Pair? 370
  • 21. xvi Contents 6.4 Sorted Array-Based List Implementation 373 The Insertion Sort 374 Unsupported Operations 375 Comparator Interface 376 Constructors 377 An Example 378 6.5 List Variations 380 Java Library Lists 380 Linked List Variations 381 A Linked List as an Array of Nodes 381 6.6 Application: Large Integers 386 Large Integers 386 The Internal Representation 387 The LargeIntList class 388 The LargeInt Class 393 Addition and Subtraction 395 The LargeIntCLI Program 404 Summary 408 Exercises 410 7 The Binary Search Tree ADT 421 7.1 Trees 423 Tree Traversals 426 7.2 Binary Search Trees 429 Binary Trees 429 Binary Search Trees 431 Binary Tree Traversals 433 7.3 The Binary Search Tree Interface 435 The Interface 436 7.4 The Implementation Level: Basics 439 7.5 Iterative Versus Recursive Method Implementations 443 Recursive Approach to the size Method 444 Iterative Approach to the size Method 446 Recursion or Iteration? 448 7.6 The Implementation Level: Remaining Observers 448 The contains and get Operations 449 The Traversals 452 7.7 The Implementation Level: Transformers 455 The add Operation 455 The remove Operation 460 7.8 Binary Search Tree Performance 466 Text Analysis Experiment Revisited 466 Insertion Order and Tree Shape 468
  • 22. Contents xvii Balancing a Binary Search Tree 469 7.9 Application: Word Frequency Counter 471 The WordFreq Class 472 The Application 473 7.10 Tree Variations 479 Application-Specific Variations 479 Balanced Search Trees 482 Summary 485 Exercises 487 8 The Map ADT 499 8.1 The Map Interface 501 8.2 Map Implementations 506 Unsorted Array 506 Sorted Array 507 Unsorted Linked List 507 Sorted Linked List 508 Binary Search Tree 508 An ArrayList-Based Implementation 508 8.3 Application: String-to-String Map 512 8.4 Hashing 516 Collisions 518 8.5 Hash Functions 524 Array Size 524 The Hash Function 525 Java’s Support for Hashing 529 Complexity 530 8.6 A Hash-Based Map 530 The Implementation 531 Using the HMap class 538 8.7 Map Variations 539 A Hybrid Structure 540 Java Support for Maps 542 Summary 542 Exercises 543 9 The Priority Queue ADT 551 9.1 The Priority Queue Interface 552 Using Priority Queues 552 The Interface 553 9.2 Priority Queue Implementations 554 Unsorted Array 554
  • 23. xviii Contents Sorted Array 554 Sorted Linked List 556 Binary Search Tree 556 9.3 The Heap 556 9.4 The Heap Implementation 562 A Nonlinked Representation of Binary Trees 562 Implementing a Heap 564 The enqueue Method 567 The dequeue Method 569 A Sample Use 574 Heaps Versus Other Representations of Priority Queues 575 Summary 576 Exercises 576 10 The Graph ADT 583 10.1 Introduction to Graphs 584 10.2 The Graph Interface 588 10.3 Implementations of Graphs 591 Array-Based Implementation 591 Linked Implementation 596 10.4 Application: Graph Traversals 597 Depth-First Searching 598 Breadth-First Searching 602 10.5 Application: The Single-Source Shortest-Paths Problem 605 Summary 611 Exercises 612 11 Sorting and Searching Algorithms 621 11.1 Sorting 622 A Test Harness 623 11.2 Simple Sorts 625 Selection Sort 625 Bubble Sort 631 Insertion Sort 635 11.3 O(N log2N) Sorts 638 Merge Sort 639 Quick Sort 646 Heap Sort 652 11.4 More Sorting Considerations 658 Testing 658 Efficiency 658 Objects and References 660
  • 24. Contents xix Comparing Objects 661 Stability 661 11.5 Searching 662 Sequential Searching 663 High-Probability Ordering 663 Sorted Collections 664 Hashing 665 Summary 666 Exercises 667 Appendix A: Java Reserved Words 673 Appendix B: Operator Precedence 674 Appendix C: Primitive Data Types 675 Appendix D: ASCII Subset of Unicode 676 Glossary 677 Index 683
  • 26. CHAPTER Getting Organized Knowledge Goals Youshouldbeableto describe some benefits of object-oriented programming describe the genesis of the Unified Method explain the relationships among classes, objects, and applications explain how method calls are bound to method implementations with respect to inheritance describe, at an abstract level, the following structures: array, linked list, stack, queue, list, tree, map, and graph identify which structures are implementation dependent and which are implementation independent describe the difference between direct addressing and indirect addressing explain the subtle ramifications of using references/pointers explain the use of O notation to describe the amount of work done by an algorithm describe the sequential search, binary search, and selection sort algorithms Skill Goals Youshouldbeableto interpret a basic UML class diagram design and implement a Java class create a Java application that uses the Java class use packages to organize Java compilation units create a Java exception class throw Java exceptions from within a class and catch them within an application that uses the class predict the output of short segments of Java code that exhibit aliasing declare, initialize, and use one- and two-dimensional arrays in Java, including both arrays of a primitive type and arrays of objects given an algorithm, identify an appropriate size representation and determine its order of growth given a section of code determine its order of growth 1 © Ake13bk/Shutterstock
  • 27. 2 Chapter 1 Getting Organized Before embarking on any new project, it is a good idea to prepare carefully—to “get organized.” In this irst chapter that is exactly what we do. A careful study of the topics of this chapter will prepare us for the material on data structures and algorithms, using the object-oriented approach, covered in the remainder of the book. 1.1 Classes, Objects, and Applications Software design is an interesting, challenging, and rewarding task. As a beginning student of computer science, you wrote programs that solved relatively simple problems. Much of your effort went into learning the syntax of a programming language such as Java: the language’s reserved words, its data types, its constructs for selection and looping, and its input/output mechanisms. As your programs and the problems they solve become more complex it is important to follow a software design approach that modularizes your solutions—breaks them into coherent manageable subunits. Software design was originally driven by an emphasis on actions. Programs were modularized by breaking them into subprograms or procedures/ functions. A subprogram performs some calculations and returns information to the call- ing program, but it does not “remember” anything. In the late 1960s, researchers argued that this approach was too limiting and did not allow us to successfully represent the constructs needed to build complex systems. Two Norwegians, Kristen Nygaard and Ole-Johan Dahl, created Simula 67 in 1967. It was the irst language to support object-oriented programming. Object-oriented lan- guages promote the object as the prime modularization mechanism. Objects represent both information and behavior and can “remember” internal information from one use to the next. This crucial difference allows them to be used in many versatile ways. In 2001, Nygaard and Dahl received the Turing Award, sometimes referred to as the “Nobel Prize of Computing,” for their work. The capability of objects to represent both information (the objects have attributes) and behavior (the objects have responsibilities) allows them to be used to represent “real- world” entities as varied as bank accounts, genomes, and hobbits. The self-contained na- ture of objects makes them easy to implement, modify, and test for correctness. Object orientation is centered on classes and objects. Objects are the basic run-time entities used by applications. An object is an instantiation of a class; alternatively, a class deines the structure of its objects. In this section we review these object-oriented pro- gramming constructs that we use to organize our programs. Classes A class deines the structure of an object or a set of objects. A class deinition includes variables (data) and methods (actions) that determine the behavior of an object. The fol- lowing Java code deines a Date class that can be used to create and manipulate Date objects—for example, within a school course-scheduling application. The Date class can be used to create Date objects and to learn about the year, month, or day of any particular
  • 28. 3 1.1 Classes, Objects, and Applications Date object.1 The class also provides methods that return the Lilian Day Num- ber of the date (the code details have been omitted—see the feature section on Lilian Day Numbers for more information) and return a string representation of the date. //---------------------------------------------------------------------- // Date.java by Dale/Joyce/Weems Chapter 1 // // Defines date objects with year, month, and day attributes. //---------------------------------------------------------------------- package ch01.dates; public class Date { protected int year, month, day; public static final int MINYEAR = 1583; // Constructor public Date(int newMonth, int newDay, int newYear) { month = newMonth; day = newDay; year = newYear; } // Observers public int getYear() { return year; } public int getMonth() { return month; } public int getDay(){ return day; } public int lilian() { // Returns the Lilian Day Number of this date. // Algorithm goes here. Code is included with the program files. // See Lilian Day Numbers feature section for details. } @Override2 public String toString() 1 The Java library includes a Date class, java.util.Date. However, the familiar properties of dates make them a natural example to use in explaining object-oriented concepts. Here we ignore the existence of the library class, as if we must design our own Date class. 2 The purpose of @Override is discussed in Section 1.2“Organizing Classes.” Authors’ Convention Java-reserved words (when used as such), user-defined identifiers, class and file names, and so on, appear in this font throughout the entire text.
  • 29. 4 Chapter 1 Getting Organized // Returns this date as a String. { return(month + / + day + / + year); } } The Date class demonstrates two kinds of variables: instance variables and class vari- ables. The instance variables of this class are year, month, and day declared as protected int year, month, day; Their values vary for each “instance” of an object of the class. Instance variables provide the internal representation of an object’s attributes. The variable MINYEAR is declared as public static final int MINYEAR = 1583; MINYEAR is deined as being static, and thus it is a class variable. It is associated di- rectly with the Date class, instead of with objects of the class. A single copy of a class vari- able is maintained for all objects of the class. Remember that the final modiier states that a variable is in its inal form and can- not be modiied; thus MINYEAR is a constant. By convention, we use only capital letters when naming constants. It is standard procedure to declare constants as class variables. Because the value of the variable cannot change, there is no need to force every object of a class to carry around its own version of the value. In addition to holding shared constants, class variables can be used to maintain information that is common to an entire class. For example, a BankAccount class may have a class variable that holds the number of current accounts. In the Date class example, the MINYEAR con- stant represents the irst full year that the widely used Gregorian calendar was in effect. The idea here is that programmers should not use the class to represent dates that predate that year. We look at ways to enforce this rule in Section 1.3 “Exceptional Situations,” where we discuss han- dling exceptional situations. The methods of the class are Date, getYear, getMonth, getDay, lilian, and toString. Note that the Date method has the same name as the class. Recall that this means it is a special type of method, called a class constructor. Constructors are used to create new instances of a class—that is, to instantiate objects of a class. The other meth- ods are classiied as observer methods, because they “observe” and return information based on the instance variable values. Other names for observer methods are “accessor” methods and “getters,” as in accessing or getting information. Methods that simply return the value of an instance variable, such as getYear() in our Date class, are very common and always follow the same code pattern consisting of a single return statement. For this reason we will format such methods as a single line of code. In addition to constructors Authors’ Convention We highlight important terms that might be unfamiliar to the student in green, the first time they are featured, to indicate that their definition can be found in the glossary in Appendix E.
  • 30. 5 1.1 Classes, Objects, and Applications and observers, there is another general category of method, called a transformer. As you probably recall, transformers change the object in some way; for example, a method that changes the year of a Date object would be classiied as a transformer. You have undoubtedly noticed the use of the access modiiers protected and public within the Date class. Let us review the purpose and use of access modiiers. This dis- cussion assumes you recall the basic ideas behind inheritance and packages. Inheritance supports the extension of one class, called the superclass, by another class, called the sub- class. The subclass “inherits” properties (data and actions) from the superclass. We say that the subclass is derived from the superclass. Packages let us group related classes together into a single unit. Inheritance and packages are both discussed more extensively in the next section. Java allows a wide spectrum of access control, as summarized in Table 1.1. The public access modiier used with the methods of Date makes them “publicly” available; any code that can “see” an object of the class can use its public methods. We say that these methods are “exported” from the class. Additionally, any class that is derived from the Date class us- ing inheritance inherits its public methods and variables. Public access sits at one end of the access spectrum, allowing open access. At the other end of the spectrum is private access. When you declare a class’s variables and methods as private, they can be used only inside the class itself and are not inherited by subclasses. You should routinely use private (or protected) access within your classes to hide their data. You do not want the data values to be changed by code that is outside the class. For example, if the month instance variable in our Date class was declared to be public, then the application code could directly set the value of a Date object’s month to strange numbers such as −12 or 27. An exception to this guideline of hiding data within a class is shown in the Date ex- ample. Notice that the MINYEAR constant is publicly accessible. It can be accessed directly by the application code. For example, an application could include the statement if (myYear Date.MINYEAR) ... Because MINYEAR is a inal constant, its value cannot be changed by the application. Thus, even though it is publicly accessible, no other code can change its value. It is not necessary Table 1.1 Java Access Control Modifiers Access Is Allowed Within the Class Within the Package Within Subclasses Everywhere public X X X X protected X X X package X X private X
  • 31. 6 Chapter 1 Getting Organized to hide it. The application code above also shows how to access a public class variable from outside the class. Because MINYEAR is a class variable, it is accessed through the class name, Date, rather than through an object of the class. Private access affords the strongest protection. Access is allowed only within the class. However, if you plan to extend your classes using inheritance, you may want to use protected access instead. The protected access modiier used in Date provides visibility similar to private access, only slightly less rigid. It “protects” its data from outside access, but allows the data to be accessed from within its own package or from any class derived from its class. Therefore, the methods within the Date class can access year, month, and day, and if, as we will show in Section 1.2 “Organizing Classes,” the Date class is extended, the methods in the extended class can also access those variables. The remaining type of access is called package access. A variable or method of a class defaults to package access if none of the other three modiiers are used. Package access means that the variable or method is accessible to any other class in the same package. 1582 1582 OCTOBER SUN 31 17 24 MON 1 18 25 TUE 2 19 26 WED 3 20 27 THU 4 21 28 FRI 15 22 29 SAT 16 23 30 Coding Convention We use protected access extensively for instance variables within our classes in this text. Lilian Day Numbers Various approaches to numbering days have been proposed. Most choose a particular day in history as day 1, and then number the actual sequence of days from that day forward with the numbers 2, 3, and so on. The Lilian Day Number (LDN) system uses October 15, 1582, as day 1, or LDN 1. Our current calendar is called the Gregorian calendar. It was established in 1582 by Pope Greg- ory XIII. At that time 10 days were dropped from the month of October, to make up for small errors that had accumulated throughout the years. Thus, the day following October 4, 1582, in the Gre- gorian calendar is October 15, 1582, also known as LDN 1 in the Lilian day numbering scheme. The scheme is named after Aloysius Lilius, an advisor to Pope Gregory and one of the principal instigators of the calendar reform. Originally, Catholic European countries adopted the Gregorian calendar. Many Protestant na- tions, such as England and its colonies, did not adopt the Gregorian calendar until 1752, at which 1582 1582 OCTOBER SUN 31 17 24 MON 1 18 25 TUE 2 19 26 WED 3 20 27 THU 4 21 28 FRI 15 22 29 SAT 16 23 30 Lilian Day Numbers Various approaches to numbering days have been proposed. Most choose a particular day in history as day 1, and then number the actual sequence of days from that day forward with the numbers 2, 3, and so on. The Lilian Day Number (LDN) system uses October 15, 1582, as day 1, or LDN 1. Our current calendar is called the Gregorian calendar. It was established in 1582 by Pope Greg- ory XIII. At that time 10 days were dropped from the month of October, to make up for small errors that had accumulated throughout the years. Thus, the day following October 4, 1582, in the Gre- gorian calendar is October 15, 1582, also known as LDN 1 in the Lilian day numbering scheme. The scheme is named after Aloysius Lilius, an advisor to Pope Gregory and one of the principal instigators of the calendar reform. Originally, Catholic European countries adopted the Gregorian calendar. Many Protestant na- tions, such as England and its colonies, did not adopt the Gregorian calendar until 1752, at which
  • 32. 7 1.1 Classes, Objects, and Applications The Unified Method The object-oriented approach to programming is based on implementing models of real- ity. But how do you go about this? Where do you start? How do you proceed? The best plan is to follow an organized approach called a methodology. In the late 1980s, many people proposed object-oriented methodologies. By the mid- 1990s, three proposals stood out: the Object Modeling Technique, the Objectory Process, and the Booch Method. Between 1994 and 1997, the primary authors of these proposals got together and consolidated their ideas. The resulting methodology was dubbed the Uniied Method. It is now, by far, the most popular organized approach to creating object- oriented systems. The Uniied Method features three key elements: 1. It is use-case driven. A use-case is a description of a sequence of actions performed by a user within the system to accomplish some task. The term “user” here should be interpreted in a broad sense and could represent another system. 2. It is architecture-centric. The word “architecture” refers to the overall structure of the target system, the way in which its components interact. time they also “lost” 11 days. Today, most countries use the Gregorian calendar, at least for official international business. When comparing historical dates, one must be careful about which calendars are being used. In our Date class implementation, MINYEAR is 1583, representing the first full year during which the Gregorian calendar was in operation. We assume that programmers will not use the Date class to represent dates before that time, although this rule is not enforced by the class. This assumption simplifies calculation of day numbers, as we do not have to worry about the phantom 10 days of October 1582. To calculate LDNs, one must understand how the Gregorian calendar works. Years are usually 365 days long. However, every year evenly divisible by 4 is a leap year, 366 days long. This aligns the calendar closer to astronomical reality. To fine-tune the adjustment, if a year is evenly divisible by 100, it is not a leap year but, if it is also evenly divisible by 400, it is a leap year. Thus 2000 was a leap year, but 1900 was not. Given a date, the lilian method of the Date class counts the number of days between that date and the hypothetical date 1/1/0—that is, January 1 of the year 0. This count is made under the assumption that the Gregorian reforms were in place during that entire time period. In other words, it uses the rules described in the previous paragraph. Let us call this number the Relative Day Number (RDN). To transform a given RDN to its corresponding LDN, we just need to subtract the RDN of October 14, 1582, from it. For example, to calculate the LDN of July 4, 1776, the method first cal- culates its RDN (648,856) and then subtracts from it the RDN of October 14, 1582 (578,100), giving the result of 70,756. Code for the lilian method is included with the program code files. time they also “lost” 11 days. Today, most countries use the Gregorian calendar, at least for official international business. When comparing historical dates, one must be careful about which calendars are being used. In our Date class implementation, MINYEAR is 1583, representing the first full year during which the Gregorian calendar was in operation. We assume that programmers will not use the Date class to represent dates before that time, although this rule is not enforced by the class. This assumption simplifies calculation of day numbers, as we do not have to worry about the phantom 10 days of October 1582. To calculate LDNs, one must understand how the Gregorian calendar works. Years are usually 365 days long. However, every year evenly divisible by 4 is a leap year, 366 days long. This aligns the calendar closer to astronomical reality. To fine-tune the adjustment, if a year is evenly divisible by 100, it is not a leap year but, if it is also evenly divisible by 400, it is a leap year. Thus 2000 was a leap year, but 1900 was not. Given a date, the lilian method of the Date class counts the number of days between that date and the hypothetical date 1/1/0—that is, January 1 of the year 0. This count is made under the assumption that the Gregorian reforms were in place during that entire time period. In other words, it uses the rules described in the previous paragraph. Let us call this number the Relative Day Number (RDN). To transform a given RDN to its corresponding LDN, we just need to subtract the RDN of October 14, 1582, from it. For example, to calculate the LDN of July 4, 1776, the method first cal- culates its RDN (648,856) and then subtracts from it the RDN of October 14, 1582 (578,100), giving the result of 70,756. Code for the lilian method is included with the program code files.
  • 33. 8 Chapter 1 Getting Organized 3. It is iterative and incremental. The Uniied Method involves a series of development cycles, with each one building upon the foundation established by its predecessors. One of the main beneits of the Uniied Method is improved communication among the people involved in the project. The Uniied Method includes a set of diagrams for this purpose, called the Uniied Modeling Language (UML).3 UML diagrams have become a de facto industry standard for modeling software. They are used to specify, visualize, con- struct, and document the components of a software system. We use UML class diagrams throughout this text to model our classes and their interrelationships. A diagram representing the Date class is shown in Figure 1.1. The diagram follows the standard UML class notation approach. The name of the class appears in the top sec- tion of the diagram, the variables (attributes) appear in the next section, and the meth- ods (operations) appear in the inal section. The diagram includes information about the nature of the variables and method parameters; for example, we can see at a glance that year, month, and day are all of type int. Note that the variable MINYEAR is underlined; this indicates that it is a class variable rather than an instance variable. The diagram also indicates the visibility or protection associated with each part of the class (+ = public, # = protected). Objects Objects are created from classes at run time. They can contain and manipulate data. Mul- tiple objects can be created from the same class deinition. Once a class such as Date has been deined, a program can create and use objects of that class. The effect is similar to expanding the language’s set of standard types to include a Date type. To create an object in Java we use the new operator, along with the class constructor, as follows: Date myDate = new Date(6, 24, 1951); Date yourDate = new Date(10, 11, 1953); Date ourDate = new Date(6, 15, 1985); Figure 1.1 UML class diagram for the Date class Date #year:int #month:int #day:int +MINYEAR:int = 1583 +Date(newMonth:int,newDay:int,newYear:int) +getYear():int +getMonth():int +getDay():int +lilian():int +toString():String 3 The official definition of the UML is maintained by the Object Management Group. Detailed information can be found at http://www.uml.org/.
  • 34. Random documents with unrelated content Scribd suggests to you:
  • 35. CHAPTER III MRS. FABIAN'S VISIT Eliza was not obliged to give up the apartment until the end of the month. Hence her drifting from day to day, and Pluto's naps in the lap of luxury. All her energy and systematic habits were in a state of suspension. Her clocks ran down. The watch in the tiny satin slipper beside her bed alone ticked the minutes away, and when Eliza wound it her eyes were too wet to see the time. Night fell and she went to bed. Morning dawned and she arose. She drank tea, but it was too much trouble to eat. One day the bell rang. At first she determined not to answer it. Then second thought came to her. What was she waiting here for except to answer the bell? Was her next duty not to introduce the usurper into his kingdom—to give into his desecrating hands those objects,— easel, palette, brushes, paints,—hallowed by her dear one's use? At the sound of a knock she hastened to fling open the door. Mrs. Fabian, elegantly gowned and furred, stood before her. Eliza gazed at this apparition dumb. Why, Eliza Brewster, exclaimed the visitor with concern, I scarcely knew you. After the mutual gaze of astonishment the caller moved in with her air of stately assurance, and Eliza followed her perforce into the living-room. Here Mrs. Fabian swiftly examined the possibilities of the scanty chairs, then seated herself in the largest. You have been ill, too, Eliza? You look like a ghost! The gaunt woman in the alpaca dress, so filled with resentment that she begrudged her own tears because they informed this relative
  • 36. of her grief, stood in silence with a beating heart. Sit down, you poor creature, went on Mrs. Fabian, unsuspecting hidden fires. They burned higher at the tone of patronage, but Eliza, weakened from mourning and lack of food, felt her knees trembling and sank into the nearest chair. Mrs. Fabian, genuinely touched by the ravages she saw, broke the silence that followed. I was greatly surprised and shocked to hear of Aunt Mary's sudden going. She began to feel uncomfortable under the set gaze of Eliza's swollen eyes. I suppose you sent to my house at once, and found that Mr. Fabian and I were in the far West. No, I didn't think of sending, returned Eliza. You should have done so. Surely there was no one nearer to Aunt Mary than I. It was in the paper, said Eliza dully. Had I been here I should, of course, have taken charge of the funeral. The pale eyes emitted a curious light. No, you wouldn't, Mrs. Fabian, was the quiet reply. Why do you say that? Because the time for you to have done something for Mrs. Ballard was while she was alive. Eliza was too spent physically to speak other than softly, but her words brought the amazed color to her visitor's face. You are presuming, Mrs. Fabian said, after a moment. What do you know about it? I suppose Aunt Mary did not think it worth while
  • 37. to tell you all the things I did for her. No, agreed Eliza, she never said a word about the times you came with your automobile to take her riding; nor the picture exhibitions you took her to see, or the way you had her to dinner Thanksgivin' time and other times, or how you had her to spend part o' the summer with you at the island, or— Eliza Brewster, what does this mean! Mrs. Fabian's eyes were dilated. Aunt Mary was not related to my husband or to his children. I never expected him to marry my family. Miss Brewster's gaze was fixed upon the speaker with pale scorn, but the latter continued with what she endeavored to make a dignified defence. I always sent Aunt Mary a present at Christmas. Yes, interrupted Eliza. Last season 'twas a paper-cutter. You gave her cuts enough without that. And I called upon her at intervals, continued the visitor in a heightened tone to drown the small voice. Intervals of a year, said Eliza. Mrs. Fabian started to rise, but bethought herself, and sank back. You are impertinent, she said coldly. A person in your position cannot understand the duties of one in mine. There can be no discussion between you and me. The speaker stirred in her chair and collected herself. I—and every one of Aunt Mary's relatives— appreciate your faithful service to her, and thank you for it. Don't you dare! ejaculated Eliza, with such sudden belligerency that Mrs. Fabian started. You're almost crazed with fatigue and grief, poor creature, she said at last. I can see that you are scarcely responsible for what you say to-day. You must take a long rest. Shall you go home to the island or take another place in town? I can find you one. Mrs. Fabian felt the superiority of her own self-control as she made this kind offer; besides, in these troublous days with servants,
  • 38. steady, reliable Eliza, with a sure touch in cookery, was not to be despised. The visitor accompanied her offer with a soothing attempt at a smile. Eliza had relapsed into dullness. I won't trouble you, she said. It would not be any trouble, was the magnanimous reply. Just let me know any time when you would like a reference, Eliza. It will give me pleasure to reward your faithfulness. Mrs. Fabian loved approval quite as much as she did admiration. She would feel much more comfortable to win that of even this uncompromising, cranky individual, so lined with the signs of suffering. As Eliza Brewster was a native of the island where Mrs. Fabian had resorted from the days of her girlhood, she had a very slight but old acquaintance with this woman. As she glanced at the thin hair, now fast turning grey, the sunken eyes and cheeks, and the bony, roughened hands, she shuddered beneath her ermine- lined sables, to remember that she and Eliza Brewster were about the same age. She passed a white-gloved hand over the firm contour of her smooth cheek as if to make sure of its firmness. I believe it was I who recommended you to Aunt Mary in the first place, long ago, she added. That's one o' your mistakes, said Eliza drily. On the contrary, returned Mrs. Fabian graciously. She was determined to warm this forlorn specimen of New England frigidity into something humanly companionable, else how was she going to attain the object of her visit? She went on with such flattery of manner as she might have employed toward a desirable débutante. It has proved quite the best thing that I ever did for Aunt Mary; securing her comfort and thereby the peace of mind of all who belonged to her. Don't call it a mistake, Eliza. However that may be, returned the other immovably, 't wa'n't you that did it. 'Twas your Cousin Mary. Oh—was it? Oh, indeed? responded Mrs. Fabian, slipping back her furs still further. Eliza Brewster's disagreeable manner was making
  • 39. her nervous. Yes, I believe Mrs. Sidney was with us on her wedding-trip just at that time. Mr. Fabian and I have just returned from visiting Mrs. Sidney out in her wild mountain home. Eliza's eyes roved involuntarily to two blank sheets of board standing on the mantelpiece; but she was silent. Do you know the contents of Aunt Mary's will, Eliza? asked Mrs. Fabian, after waiting vainly for an inquiry as to her cousin's well- being. I do. What do you think of it? That don't matter, does it? A streak of light illumined Mrs. Fabian's annoyance. Ah, that was what was the matter with Eliza. After twenty-five years of faithful service, she had expected to inherit her mistress's few hundreds. Full explanation, this, of the present sullenness. The disappointment must, indeed, have been bitter. Mrs. Fabian felt an impulse of genuine sympathy. She knew the singular loneliness of Eliza's situation; knew that she had no near kin, and the transplanting from the island home had been complete. What an outlook now, was Eliza Brewster's! Perhaps the will was as much of a surprise to you as it was to the rest of us, Mrs. Fabian went on. The Sidneys were amazed. They didn't tell me just how much Aunt Mary left young Mr. Sidney. Do you know? Yes, replied Eliza promptly. And again Mrs. Fabian looked at her interrogatively. As well question the Sphinx. She comprehended the stony closing of the thin lips. There might be a combination which would make them open, but she did not have it. She shrugged her fine-cloth shoulders. Oh, well, it doesn't matter. It must have been very little, anyway.
  • 40. She sighed. She must get at her business, though she dreaded absurdly to introduce it. Well, Eliza, if you will take me to Aunt Mary's room, I will go through her belongings. It is always the most painful duty connected with a death, but it cannot be escaped. Eliza stared at her, speechless. Aunt Mary had a few very nice things, went on Mrs. Fabian. She tried to smile as at a loving memory. The regulation treasures of a dear old lady,—her diamond ring, a diamond brooch, and a camel's hair shawl—My heavens! cried the visitor, interrupting herself suddenly with a shriek of terror. Take it away! Take it away! She clung to the back of her chair; for Pluto, silent as a shadow, had sprung upon the ends of her pelerine as they lay in her lap and was daintily nosing the fur, while perilously grasping its richness, his eyes glowing with excitement. Eliza rose, and sweeping him into one arm resumed her seat. Oh, how that frightened me! Mrs. Fabian panted and looked angrily at the animal with the jetty coat and abbreviated tail, whose eyes, live emeralds, expanded and contracted as they glowed still upon the coveted fur. If she expected an apology, none came. Eliza's pale face showed no emotion. Endurance was written in every line. To be interrupted at such a critical moment! Mrs. Fabian felt it was unbearable. Let me see—she began again with a little laugh. Your pet knocked everything out of my head, Eliza. Oh, yes, I was saying that I will look over Aunt Mary's things now. She rose as she spoke. Eliza kept her seat. You can't do that, Mrs. Fabian. I certainly shall, Eliza Brewster. What do you mean? I mean that they're mine. She left 'em all to me.
  • 41. The speaker struggled to control the trembling of her lips. The visitor looked the limp black alpaca figure over, haughtily. Aunt Mary left you her diamond ring, her diamond brooch, and her camel's hair shawl? she asked sceptically. She left her diamond brooch to her namesake, Mrs. Sidney. I sent it to her a week ago. Then, since you know Aunt Mary's wishes, what did she leave me? The ring? No, ma'am! The shawl? No, ma'am. Mrs. Fabian's nostrils dilated. My aunt's poor trifles are nothing to me, of course, except for sentiment's sake, she said haughtily. Eliza bowed her bitter face over Pluto's fur. I am quite sure, however, that she did not pass away without some mention of me,—her sister's child. She did, though, Mrs. Fabian. If it's a keepsake you want, added Eliza drily, you may have the paper-cutter. It's never been out o' the box. The visitor, still standing, eyed the other with compressed lips before she spoke:— I have told you that I don't consider you responsible to-day. You are half-crazed, and I'm sorry for you. Answer me this, however, and mind, I shall verify your words by a visit to Mrs. Ballard's lawyer. Did my aunt leave you, legally, all her personal possessions? She did. Mrs. Fabian maintained another space of silence, gazing at the seated figure, whose gown looked rusty behind the polished lynx-
  • 42. black pressed against it. There was no mistaking the truth in the pale, wretched eyes. Disappointed about the money, though, and taking out her ill temper on me, thought the visitor. To Eliza's increased heaviness of heart, the lady resumed her seat. Aunt Mary's death was sudden and unexpected and that explains her not speaking of me, she said; but I know it would please her that I should use something that she had owned. I remember that shawl as being a very good one. It came to her from some of her husband's people. I'll buy that of you, Eliza. Will you? returned the other, and Pluto emitted an indignant yowl and tried to leap from the tightening hold. Don't you let him go, Eliza! cried Mrs. Fabian in a panic. He's crazy about my fur. They always are.—Yes, the shawl is of no use to you and the money will be. It is so fine, it would be wicked to cut it into a wrap. I shall spread it on my grand piano. Silence, while Eliza struggled still to control the trembling lips, and Pluto twisted to escape her imprisoning arm. I'm willing to give you twenty-five dollars for that shawl. Mrs. Fabian waited, and presently Eliza spoke:— It ain't enough, she said, against her impeding breath. Fifty, then. We all feel grateful to you. Mrs. Fabian, Eliza sat up in her chair as if galvanized and looked her visitor in the eyes, while she spoke with unsteady solemnity, the price o' that shawl is one million dollars. The visitor stared at the shabby figure with the grey, unkempt locks, then shrugged her shoulders with a smile. You'll come to your senses, Eliza, she said. Some day that fifty dollars will look very good to you. I'll hold the offer open—
  • 43. Likewise, added Eliza, breaking in upon her words with heightened voice, but the same deliberation, that is the price of each handkerchief she left me, and each one of her little, wornout slippers, and her— She could get no further. She choked. Mrs. Fabian rose; Pluto, with another cry and a supreme writhe, tore himself from his iron prison. The visitor shuddered, and looked at him fearfully, as his eager eyes seemed to threaten her. She hastened precipitately toward the door. Eliza, putting the utmost constraint upon herself, rose and ushered her out. Mrs. Fabian uttered a brief good-bye. Eliza was beyond speech. While the visitor entered her waiting car, and sank with relief among its cushions, the mourner stood, her back against the closed door, and her eyes closed. Restrained drops ran down her cheeks in well-worn ruts, and occasionally a spasmodic sob shook the slight form. Pluto came to her feet, his short tail stiffly outstretched and his half- closed eyes lifted to the sightless face. In the long silence he rubbed himself against her feet in token of forgiveness.
  • 44. CHAPTER IV PHILIP SIDNEY The Fabians had given Philip Sidney a pressing invitation to spend his first week in New York with them. When he arrived, however, and announced himself at the house, through some misunderstanding there was no one there to receive him save the servants. A comely maid apologized for the absence of her mistress, saying that Mr. Sidney had not been expected until the following day; and showing him to his room she left him to his own devices. Emerging from his bath and toilet, he found Mrs. Fabian not yet returned. It was but four o'clock, and he decided to go to the Ballard apartment and attend to his errand there. Eliza had been doing some sweeping, the need for it goading her New England conscience to action. Her brown calico dress was pinned up over her petticoat, and her stern, lined face looked out from a sweeping-cap. There sounded suddenly a vigorous knock on her door. She scowled. Some fresh agent, I s'pose, she thought. Too sly to speak up the tube. Broom in hand, she strode to the door and pulled it open with swift indignation. Why didn't you ring? she exclaimed fiercely. We don't want— She paused, her mouth open, and stared at the young man who pulled off a soft felt hat, and looked reassuring and breezy as he smiled.
  • 45. I did ring, but it was the wrong apartment. There was no card downstairs, so I started up the trail. Is this Mrs. Ballard's? The frank face, which she instantly recognized, and the clear voice that had a non-citified deliberation, accused Eliza of lack of hospitality; and she suddenly grew intensely conscious of her cap and petticoat. Come in, she said. I was doin' some sweepin'. The first— she paused abruptly and led the way down the corridor to the shabby living-room. Phil's long steps followed her while his eyes shone with appreciation of the drum-major effect of the cap and broom, and the memory of his fierce greeting. I don't wonder Aunt Mary died, he thought. I would too. Meanwhile Eliza's heart was thumping. This interview was the climax of all she had dreaded. The usurper had an even more manly and attractive exterior than she had expected, but well she knew the brutal indifference of youth; the selfishness that takes all things for granted, and that secretly despises the treasures of the old. The haste with which she set the broom in the corner, unpinned her dress, and pulled off her cap, was tribute to the virile masculinity of the visitor; but the stony expression of her face was defence from the blows which she felt he would deliver with the same airy unconsciousness that showed in the swing of his walk. You're Eliza Brewster, I'm sure, he said. My mother knew you when she was a girl. The hasty removal of Eliza's cap had caused a weird flying-out of her locks. The direct gaze bent upon her twinkled. I wonder if she'd let me paint her as Medusa, he was thinking; while her unspoken comment was: And she never saw his teeth! It's just as well.
  • 46. Yes, that's who I am, she said. Sit down, Mr. Sidney. I've been expectin' you. You didn't behave that way, he replied good-naturedly, obeying. I thought at first I was going downstairs quicker than I came up, and I'd taken them three at a time. His manner was disarming and Eliza smoothed her flying locks. The agents try to sneak around the rules o' the house, she said briefly. So this is where Aunt Mary lived. He looked about the room with interest. We people in God's country hear about these flats where you don't dare keep a dog for fear it'll wag its tail and knock something over. The troublesome lump in Eliza's throat had to be swallowed, so the visitor's keen glance swept about the bare place in silence. I see she didn't go in much for jim-cracks, he added presently. Eliza's lump was swallowed. Mrs. Ballard didn't care for common things, she said coldly. She was an artist. Phil comprehended vaguely that rebuke was implied, and he met the hard gaze as he hastened to reply:— Yes, yes, I understand. An increase of the pathos he had always discerned since learning about his great-aunt, swept over him now, face to face with the meagreness of her surroundings. Did Aunt Mary work in this room? I see an easel over there. Yes, she worked here. The reply came in an expressionless voice. Poor Aunt Mary! thought the visitor. No companion but this image! Eliza exerted heroic self-control as she continued: I've got the things packed up for you—the paints, and brushes, and palette. The easel's yours, too. Do you want to take 'em to-day?
  • 47. Would it be a convenience to you if I did? Are you going to give up the flat immediately? In a week. Then I'll leave them a few days if you don't mind while I'm looking for a room. I haven't an idea where to go. I'm more lost here than I ever was in the woods; but the Fabians will advise me, perhaps. Mrs. Fabian has been here to see you, I suppose. Eliza's thin lips parted in a monosyllable of assent. What a wooden Indian! thought Phil. Nevertheless, being a genial soul and having heard Miss Brewster's faithfulness extolled, he talked on: We hear about New York streets being canyons. They are that, and the sky-line is amazing; but the noise,—great heavens, what a racket! and I can't seem to get a breath. The young fellow rose restlessly, throwing back his shoulders, and paced the little room, filling it with his mountain stride. Eliza Brewster watched him. She thought of her mistress, and the pride and joy it would have been to her to receive this six feet of manhood under her roof. She wouldn't 'a' kept her sentimental dreams long, reflected Eliza bitterly. He'd 'a' hurt her, he'd 'a' stepped on her feelin's and never known it. He walks as if he had spurs on his boots. She steeled herself against considering him through Mrs. Ballard's eyes. He's better-lookin' than the picture, she thought, and I wouldn't trust a handsome man as far as I could see him. They haven't any business with beauty and it always upsets 'em one way or another—yes, every time. Her eyes wandered to the mantelpiece whose bareness was relieved only by three varying sized pieces of blank paper. She felt the slightest quiver of remorse as she looked. She seemed to see her mistress's gentle glance filled with rebuke. She stirred in her chair, folded her arms, and cleared her throat.
  • 48. You can leave the things here till I go, if you want to, she said. Phil paused in his promenade and regarded her. Her manner was so unmistakably inimical that for the first time he wondered. Perhaps, after all, she was not just a machine. And the same thought which had been entertained by Mrs. Fabian occurred to him. Twenty-five years of faithful service, he reflected. I wonder if she expected the money? She's sore at me. That's a cinch. Phil's artist nature grasped her standpoint in a flash. The granite face, with its signs of suffering, the loneliness, the poverty, all appealed to him to excuse her disappointment. His eyes swept about the bare walls. Where are Aunt Mary's pictures? he asked. Was she too modest to hang them? There were some up there, replied Eliza. I took 'em down. The visitor's quick eyes noted the white boards on the mantelpiece. With an unexpected movement, he strode across to it, and turned them around. He stood in the same position for a space. Great guns, but she hates me! he thought, while Eliza, startled, felt the shamed color stream up to her temples. What would Mrs. Ballard say! was her guilty reflection. Pluto here relieved the situation by making a majestic entrance. His jewel eyes fixed on the stranger for a moment with blinking indifference, then he proceeded, with measured tread, toward the haven of his mistress's lap. Hello, Katze, said Phil, stooping his scarlet face. He seized the creature by the nape of its neck and instantly the amazed cat was swung up to his broad shoulder, where it sat, claws digging into his coat and eyes glowering into his own.
  • 49. Say, charcoal would make a white mark on you, pussy, he went on, smoothing the creature in a manner which evidently found favor, for Pluto did not offer to stir. When I'm not doing her as Medusa, he reflected, I'll paint her as a witch with this familiar. She'll only have to look at the artist to get the right expression. A distinguished visitor from the island of Manx, I suspect, he said aloud. No, returned Eliza, still fearfully embarrassed. Pluto was born right here in New York. The ever-ready stars in the visitor's eyes twinkled again into the green fire opposite them. It was his tail I was noticing. Manx cats are like that. Oh, that was boys. If I could 'a' caught 'em I'd 'a' liked to cut off their arms. I'll bet on that, thought Phil, and their legs too. Eliza cleared her throat. She seemed still to see the gentle eyes of her lost one rebuking her. With utter disregard of a future state she was preparing a lie. About those sketches, she said presently, and such was her hoarseness that she was obliged to clear her throat again, you see, I was—sweepin', and I turned 'em to the wall. Oh, yes, said Phil, and continued to smooth Pluto who purred lustily. A pretty good one for New England, he thought; and carelessly turning the third card about, he came face to face with his own photograph. With one glance of disgust he tore the picture in two and threw it down. Eliza started. What did you do that for? she demanded sharply. Phil made a motion of impatience.
  • 50. Oh, it's so darned pretty! he explained. I thought all those pictures were in the fire. Mrs. Ballard set great store by that, said Eliza coldly, and by the sketches, too, she added. She was sitting up stiffly in her chair, now, and her gaze fixed on Phil, as, her cat on his shoulder singing loud praise of his fondling hand, he came and stood before her. I wish you'd let me see some of Aunt Mary's pictures, he said. The dead woman's letter was against his heart. He felt that they were standing together, opposed to the hard, grudging face confronting him. But this was Eliza's crucial moment. In spite of herself she feared in the depths of her heart that that which Mrs. Ballard had said was true; that this restless, careless boy had an artistic ability which her dear one had never attained. She shrank with actual nausea from his comments on her mistress's work. He might not say anything unkind, but she should see the lines of his mouth, the quiver of an eyelash. She felt unable to rise. She left 'em all to me, she said mechanically, pale eyes meeting dark ones. Phil brushed Pluto's ears and the cat sang through the indignity. Talk about the bark on a tree! he thought. I believe I'll paint her as a miser, after all! She'd be a wonder, with Pluto standing guard, green eyes peering out of the shadow. He smiled down at Eliza, the curves of his lips stretching over the teeth she had admired. All right, he said. I'm not going to take them away from you. Eliza forced herself to her feet, and without another word slowly left the room.
  • 51. Phil met the cat's blinking eyes where the pupils were dilating and contracting. Katze, this place gives me the horrors! he confided. More than once on the train he had read over his aunt's letter, and each time her words smote an answering chord in his heart and set it to aching. The present visit accentuated the perception of what her life had been. For a moment his eyes glistened wet against the cat's indolent contentment. I wish she hadn't saved any money, the poor little thing, he muttered. No friends, no sympathy—nothing but that avaricious piece of humanity, calculating every day, probably, on how soon she would get it all. I'll paint her as a harpy. That's what I'll do. Talons of steel! That's all she needs. He heard a sound and dashed a hand across his eyes. Eliza, heavy of heart, stony of face, entered, a number of pictures bound together, in her hands. The visitor darted forward to relieve her, and Pluto drove claws into his suddenly unsteady resting-place. Eliza yielded up her treasures like victims, and stood motionless while Phil received them. Never had she looked so gaunt and grey and old; but the visitor did not give her a glance. Aunt Mary's letter was beating against his heart. Here was the work her longing hands had wrought, here the thwarting of her hopes. His fingers were not quite steady as he untied the strings, and moving the easel into a good light placed a canvas upon it. Eliza did not wish to look at him, but she could not help it. Her pale gaze fixed on his face in a torture of expectation, as he backed away from the easel, his eyes on the picture. Pluto rubbed against his ear as a hint that caressing be renewed. He stood in silence, and Eliza could detect nothing like a smile on his face.
  • 52. Presently he removed the canvas, and took up another. It was the portrait of Pluto. Hello, Katze. Got your picture took, did you? Aunt Mary saw your green shadows all right. He set the canvas aside, and took up another. Eliza's muscles ached with tension. Her bony hands clasped as she recognized the picture. To the kittens over the table in the kitchen she had once confided that this landscape, which the artist had called Autumn, looked to her eyes like nothing on earth but a prairie fire! It had been a terrible moment of heresy. She was punished for it now. Phil backed away from the canvas, and elbow in his hand, rested his finger on his lips for what seemed to Eliza an age. Her heart thumped, but she could not remove her gaze from him. Pluto, finding squirming and rubbing of no avail, leaped to the floor and blinked reflectively at his mistress. A flagpole would have offered equal facilities for cuddling. He therefore made deliberate selection of the least unsatisfactory chair, and with noiseless grace took possession. Phil nodded. Yes, sir, he murmured; yes, sir. Eliza's teeth bit tighter on her suffering under lip. What did Yes, sir mean? At least he was not smiling. He went on, slightly nodding, and thinking aloud; Aunt Mary was ahead of her time. She knew what she was after. Eliza tried to speak, and couldn't. Something clicked in her throat. Phil went on regarding the autumnal tangle, and with a superhuman effort Eliza commanded her tongue. What was that you said, Mr. Sidney? Phil, again becoming conscious of the stony presence, smiled a little. Aunt Mary would have found sympathizers in Munich, he said. That's Germany, ain't it? said Eliza, words and breath interlocking.
  • 53. Yes. Most of Uncle Sam's relatives want to see plainer what's doing; at least those who are able to buy pictures. Ahead of her time! gasped Eliza, her blood racing through her veins. Ought to 'a' been in Germany! And then the most amazing occurrence of Philip Sidney's life took place. There was a rush toward him, and suddenly his Medusa, his witch, his miser, his harpy was on her knees on the floor beside him, covering his hand with tears and kisses, and pouring out a torrent of words. I've nearly died with dread of you, Mr. Sidney. Oh, why isn't she here to hear you say those words of her pictures! Nobody was ever kind to her. Her relations paid no more attention to her, or her work, than if she'd been a—a—I don't know what. She was poor, and too modest, and the best and sweetest creature on earth; and when your sketches came she admired 'em so that I began to hate you then. Yes, Mr. Sidney, you was a relative, and goin' to be a success, and the look in her eyes when she saw your work killed me. It killed me! Do, do get up, said Philip, trying to raise her. Don't weep so, Eliza. I understand. But the torrent could not yet be stemmed. I've looked forward to your comin' like to an operation. I've thought you might laugh at her pictures, 'cause young folks are so cruel, and they don't know! Let me cry, Mr. Sidney. Don't mind! You've given me the first happy moment I've known since she left me. I was the only one she had, even to go to picture galleries with her, and my bones ached 'cause I was a stupid thing, and she had wings just like a little spirit o' light. Philip's lashes were moist again. I wish I had been here to go with her, he said. Eliza lifted her streaming eyes. Would you 'a' gone? she asked, and allowed Phil to raise her gently to her feet.
  • 54. Indeed, I would, he answered gravely, and we should have lived together, and worked together. Oh, why couldn't it 'a' been! Why couldn't it 'a' been! What it would 'a' meant to her to have heard what you said just now about her pictures! Phil's hands were holding Eliza's thin shoulders, and her famished eyes were drinking in the comfort of him. I have an idea that we ought not to believe that we could make her happier than she is, he said, with the same gravity. I know, faltered Eliza, surprised; of course that's the way I ought to feel; but there wasn't ever anything she cared much about except paintin'. She—Eliza swallowed the tremulous sob that was the aftermath of the storm—she loved music, but she wasn't a performer. Phil smiled into the appealing face. Then she's painting, for all we know, he said. Do you believe music is all that goes on there? It's all that's mentioned, said Eliza apologetically. I have an idea that dying doesn't change us any, said the young man. Why should it? It didn't need to change her, agreed the other, her voice breaking. I believe that in the end we get what we want. That's comfortin'. Not so you'd notice it, returned Phil with conviction. It makes the chills run down my spine occasionally when I stop to realize it. What do you mean? Only that we had better examine what we're wanting; and choose something that won't go back on us. Aunt Mary did; and I believe she had a strong faith.
  • 55. We never talked religion, said Eliza. Just lived it. That's better. I didn't, returned Eliza, a spark of the old belligerency flashing in her faded eyes. I can't think of one single enemy that I love! You were everything to Aunt Mary. Do you suppose I shall ever forget that? I sat down in front o' those pictures in the Metropolitan Museum, said Eliza, her lips trembling again. It's awful big, and I got so tuckered, the pictures sort o' ran together till I didn't know a landscape from a portrait. Then I used to take on over somethin' that had a seat in front of it, and she'd leave me sittin' there starin'. Oh, Mr. Sidney, I can't think o' one other mean thing I ever did to her,—remorseful grief shook the speaker's voice,—but I'd ought to 'a' stood up to the end. It would 'a' showed more interest! Phil squeezed the spare shoulders as they heaved. He laughed a little. Now, Eliza, whatever way you managed it, I know you made her happy. Yes, groaned the repentant one, she said my artistic soul was wakin' up. Do you s'pose where she is now she knows it was black deceit? She knows nothing black where she is,—Phil's voice rang with decision; but she does know more than ever about love and sacrifice such as you have shown her. Beside, in a lighter tone, how about your artistic soul? See how far above everybody else you understood her pictures. Eliza's hungry gaze became suddenly inscrutable. Mr. Sidney, she began, after a pause, I loved every stroke her dear hand made, but—again pain crept into the breaking voice—you said yourself America wasn't worthy of her, and I'm only what you might call the scum of America when it comes to insight and—and expression and —and atmosphere. Usually I had sense enough to wait till she told
  • 56. me what a thing was before I talked about it; but one day, I can't ever forget it, I praised a flock o' sheep at the back of a field she was doin' and she said they was—was cows! Sobs rent the speaker and she covered her eyes. I told her—'twas my glasses, she went on when she could speak. I—told her they—hadn't been right for—a long time. She laughed— and tried to make a joke of it, but— Eliza's voice was drowned in the flood. Phil patted her shoulders and smiled across the bowed head at the forlorn mantelpiece, where the sketches, unconscious of forgiveness, still turned faces toward the wall. You've grown awfully morbid, alone here, he said, giving her a little shake. You should be only thankful, as I am, that Aunt Mary had you and that you were here to take care of her to the end. Come and sit down. She wrote me a wonderful letter. I have it in my pocket and I'll show it to you. Eliza obediently yielded herself to be guided to a chair. Pluto had selected the best with unerring instinct; and suddenly into his feline dreams an earthquake intruded as Phil tossed him lightly to the floor. Drawing his chair close to Eliza, who had wilted back against the faded cretonne roses, the young man drew from his pocket an envelope and took out of it a letter, and a small card photograph. Mother gave me this old picture of Aunt Mary— Eliza pulled herself up and took it eagerly. I must get my glasses, she said. I've cried myself nearly blind. Phil's big hand pushed her back. I'll get them, he returned. Where are they? There, on the end o' the mantelpiece. I had 'em, readin' an advertisement.
  • 57. She leaned back again and watched him as he crossed the room; watched him with wonder. In years she had not so given her confidence to a human being. She put on the spectacles and wistfully regarded the picture of a pretty woman whose heavy braids, wound around her head, caught the light. Her plain dress was white and she wore black velvet bands on her wrists. Aunt Mary was considered different by her friends, mother says. In a time of frills she liked plain things. I guess she was different, agreed Eliza devoutly. Would you think a man who married her would like whiskey better? Phil shook his head. Sorry, he said, laconically. One good thing, he drank himself to death quick and left her free. Phil held out the letter. Read it to me, please, Mr. Sidney. Can't do it, returned the young man with cheerful frankness. It makes my nose tingle every time. So Eliza read the letter in silence. It took her some minutes and when she had finished, her lip caught between her teeth, she took off her glasses and wiped them while she regarded Phil. And you've got to live up to that, she said. I'm going to try, he answered simply. Eliza gazed at him, her hands in her lap. She felt old beside his youth, weak beside his strength, ignorant beside that knowledge which had stirred her mistress to exaltation. Nevertheless, the humble love, and desire to help him that swelled her heart was a new desire to live, a consecration. Presently he took his leave, promising to return in a few days for his belongings.
  • 58. After the door had closed behind him, she looked down at the cat, who had awakened from another nap at the stir of the departure. He rubbed against her brown calico skirt as she lighted the gas; then she moved thoughtfully to the mantelpiece and turned the sketches about. Mary Sidney, she mused, looking at the graceful head of Phil's mother, you've had your heartache, and your sacrifices. You've been most pulled in two, between longin' to stay with your husband and follow your son—you told me somethin' of it in your note thankin' for the brooch. Nobody escapes, Mary Sidney. I guess I haven't done you justice, seein' you've raised a boy like that. Turning to the sketch of the storm-beaten tree, she clasped her hands before it. Dear one, she mused tenderly, you loved him. You was great. You died not knowin' how great you were; and you won't care if I do understand this kind better, 'cause all America's too ignorant for you, and I'm one o' the worst. Her eyes dwelt lingeringly on the sketch. She fancied she could hear the wind whistling through the writhing branches. It looks like my life, she thought, risin' out o' the mist and the cloud. She gazed at it in silence, then turned to the destroyed photograph. She seized the pieces quickly and turned them face up. The rent had missed the chin and cut across the collar. She regarded the face wistfully. The cat stretched his forepaws up her skirt until he was of a preternatural length. It was supper-time. I wonder, Pluto, she said slowly, if I couldn't fit that into a minicher frame. Some of 'em come real reasonable.
  • 59. CHAPTER V ELIZA'S INVITATION For the first time since she had been left alone, Eliza drank her tea that night without tears; and no lump in her throat prevented her swallowing the egg she had boiled. She held Mrs. Ballard's watch in her hand a minute before getting into bed; and looked long at its gold face, and listened to its loud and busy ticking. Forgive me, Mrs. Ballard, she thought; and association added, as we forgive our debtors! No, I can't! she muttered fiercely. I can't! What's the use o' pretendin'! Muffling the watch in its slipper, she turned out the gas and got into bed. Composing herself to sleep more peacefully than she had been able to do for many a night, her last thought was of Mrs. Ballard's heir; and a sense of comfort stole over her in the very fact of his existence. Again she seemed to feel the sympathetic pressure of his kind hand. He thinks she may be paintin' still, she reflected. She's got colors to work with that's most blindin', they're so gorgeous, if we can judge anything by the sunsets at the island. Why not think so! It's just as reasonable as playin' harps, for all I can see. Ever since her dear one's passing, Eliza had felt too crushed and too wicked to pray; and being unable to say the whole of her Lord's Prayer, her New England conscience would not allow her to say any of it; but to-night a sense of hope and gratitude lightened the
  • 60. Welcome to our website – the ideal destination for book lovers and knowledge seekers. With a mission to inspire endlessly, we offer a vast collection of books, ranging from classic literary works to specialized publications, self-development books, and children's literature. Each book is a new journey of discovery, expanding knowledge and enriching the soul of the reade Our website is not just a platform for buying books, but a bridge connecting readers to the timeless values of culture and wisdom. With an elegant, user-friendly interface and an intelligent search system, we are committed to providing a quick and convenient shopping experience. Additionally, our special promotions and home delivery services ensure that you save time and fully enjoy the joy of reading. Let us accompany you on the journey of exploring knowledge and personal growth! textbookfull.com