(eBook PDF) Data Structures and Other Objects Using Java 4th Edition download
(eBook PDF) Data Structures and Other Objects Using Java 4th Edition download
https://ebookluna.com/product/ebook-pdf-data-structures-and-
other-objects-using-java-4th-edition/
(eBook PDF) Data Structures and Problem Solving Using Java 4th Edition
https://ebookluna.com/product/ebook-pdf-data-structures-and-problem-
solving-using-java-4th-edition/
(eBook PDF) Data Structures and Abstractions with Java 4th Edition
https://ebookluna.com/product/ebook-pdf-data-structures-and-abstractions-
with-java-4th-edition/
(eBook PDF) Data Structures and Abstractions with Java 4th Global Edition
https://ebookluna.com/product/ebook-pdf-data-structures-and-abstractions-
with-java-4th-global-edition/
(eBook PDF) Starting Out with Java: From Control Structures through Data
Structures 4th Edition
https://ebookluna.com/product/ebook-pdf-starting-out-with-java-from-
control-structures-through-data-structures-4th-edition/
Data Structures and Abstractions with Java 5th Edition (eBook PDF)
https://ebookluna.com/product/data-structures-and-abstractions-with-
java-5th-edition-ebook-pdf/
(eBook PDF) Starting Out with Java: From Control Structures through
Objects, 7th Edition
https://ebookluna.com/product/ebook-pdf-starting-out-with-java-from-
control-structures-through-objects-7th-edition/
(eBook PDF) Starting Out with Java: From Control Structures through Data
Structures 3rd Edition
https://ebookluna.com/product/ebook-pdf-starting-out-with-java-from-
control-structures-through-data-structures-3rd-edition/
https://ebookluna.com/product/ebook-pdf-introduction-to-java-programming-
and-data-structures-comprehensive-version-11/
https://ebookluna.com/product/ebook-pdf-java-foundations-introduction-to-
program-design-and-data-structures-5th-edition/
Preface vii
Step 3: Use the Data Type. With the specification in place, students can write
small applications or applets to show the data type in use. These applications are
based solely on the data type’s specification because we still have not tied down
the implementation.
the data types in One of the lasting effects of the course is the specification, design, and imple-
this book are mentation experience. The improved ability to reason about programs is also
cut-down important. But perhaps most important of all is the exposure to classes that are
versions of the easily used in many situations. The students no longer have to write everything
Java Class from scratch. We tell our students that someday they will be thinking about a
Libraries problem, and they will suddenly realize that a large chunk of the work can be
done with a bag, a stack, a queue, or some such. And this large chunk of work is
work that they won’t have to do. Instead, they will pull out the bag or stack or
queue that they wrote this semester—using it with no modifications. Or, more
likely, they will use the familiar data type from a library of standard data types,
such as the proposed Java Class Libraries. In fact, the behavior of some data
types in this text is a cut-down version of the JCL, so when students take the step
to the real JCL, they will be on familiar ground—from the standpoint of how to
use the class and also having a knowledge of the considerations that went into
building the class.
Java Objects. The Java Object type lies at the base of all the other Java
types—or at least almost all the other types. The eight primitive types are not
Java objects, and for many students, the CS1 work has been primarily with the
eight primitive types. Because of this, the first few data structures are collec-
tions of primitive values, such as a bag of integers or a sequence of double num-
bers.
Iterators. Iterators are an important part of the Java Class Libraries, allowing
a programmer to easily step through the elements in a collection class. The
Iteratable interface is introduced in Chapter 5. Throughout the rest of the
text, iterators are not directly used, although they provide a good opportunity for
programming projects, such as using a stack to implement an iterator for a
binary search tree (Chapter 9).
Chapter Dependencies
Chapter 1
Introduction
Chapters 2–3
Classes
Reference variables
Collection classes Chapter 8
Recursion
Chapter 2 can be skipped by students
with a good background in Java classes.
Section 11.1
Chapter 4
Binary search
Linked lists
Chapter 13
Extended classes
Sections 5.1–5.4 Sec. 11.2–11.3
Generic programming Hash tables
(Also requires
Chapter 5)
Sections 5.5–5.7 Chapter 6
The Java API Stacks
Chapter 12
Iterators Sorting
Java collections (Heapsort also
Java maps Chapter 7 Chapter 9
needs Section
Queues Trees
10.1)
including time for exams and extra time for linked lists and trees. Remaining
weeks can be spent on a tree project from Chapter 10 or on binary search (Sec-
tion 11.1) and sorting (Chapter 12).
Heavy OOP Emphasis. If students will cover sorting and searching else-
where, then there is time for a heavier emphasis on object-oriented program-
ming. The first three chapters are covered in detail, and then derived classes
(Section 13.1) are introduced. At this point, students can do an interesting OOP
project, perhaps based on the ecosystem of Section 13.3. The basic data struc-
tures (Chapters 4 –7) are then covered, with the queue implemented as a derived
class (Section 13.4). Finish up with recursion (Chapter 8) and trees (Chapter 9),
placing special emphasis on recursive methods.
Accelerated Course. Assign the first three chapters as independent reading in
the first week and start with Chapter 4 (linked lists). This will leave two to three
extra weeks at the end of the term so that students can spend more time on
searching, sorting, and the advanced topics (shaded in the chapter dependencies
list).
I also have taught the course with further acceleration by spending no lecture
time on stacks and queues (but assigning those chapters as reading).
Early Recursion / Early Sorting. One to three weeks may be spent at the
start of class on recursive thinking. The first reading will then be Chapters 1 and
8, perhaps supplemented by additional recursive projects.
If the recursion is covered early, you may also proceed to cover binary search
(Section 11.1) and most of the sorting algorithms (Chapter 12) before introduc-
ing collection classes.
Acknowledgments
This book grew from joint work with Walter Savitch, who continues to be an
ever-present and enthusiastic supporter, colleague, and friend. My students from
the University of Colorado at Boulder serve to provide inspiration and joy at
every turn, particularly the spring seminars in Natural Computing and Ideas in
Computing. During the past few years, the book has also been extensively
reviewed by J.D. Baker, Philip Barry, Arthur Crummer, Herbert Dershem, Greg
Dobbins, Zoran Duric, Dan Grecu, Scott Grissom, Bob Holloway, Rod Howell,
Danny Krizanc, Ran Libeskind-Hadas, Meiliu Lu, Catherine Matthews, Robert
Moll, Robert Pastel, Don Slater, Ryan Stansifer, Deborah Trytten, and John
Wegis. I thank these colleagues for their excellent critique and their encourage-
ment.
At Addison-Wesley, I thank Tracy Dunkelberger, Michael Hirsch, Bob
Engelhardt, and Stephanie Sellinger, who have provided continual support and
knowledgeable advice.
I also thank my friends and colleagues who have given me daily
encouragement and friendship during the writing of this fourth edition: Andrzej
Ehrenfeucht, Marga Powell, Grzegorz Rozenberg, and Allison Thompson-
Brown, and always my family: Janet, Tim, Hannah, Michelle, and Paul.
Chapter List
APPENDIXES 775
INDEX 815
Contents xv
Contents
CHAPTER 1 THE PHASES OF SOFTWARE DEVELOPMENT 1
1.1 Specification, Design, Implementation 4
Design Technique: Decomposing the Problem 5
How to Write a Specification for a Java Method 6
Pitfall: Throw an Exception to Indicate a Failed Precondition 9
Temperature Conversion: Implementation 10
Programming Tip: Use Javadoc to Write Specifications 13
Programming Tip: Use Final Variables to Improve Clarity 13
Programming Tip: Make Exception Messages Informative 14
Programming Tip: Format Output with System.out.printf 14
Self-Test Exercises for Section 1.1 15
1.2 Running Time Analysis 16
The Stair-Counting Problem 16
Big-O Notation 21
Time Analysis of Java Methods 23
Worst-Case, Average-Case, and Best-Case Analyses 25
Self-Test Exercises for Section 1.2 26
1.3 Testing and Debugging 26
Choosing Test Data 27
Boundary Values 27
Fully Exercising Code 28
Pitfall: Avoid Impulsive Changes 29
Using a Debugger 29
Assert Statements 29
Turning Assert Statements On and Off 30
Programming Tip: Use a Separate Method for Complex Assertions 32
Pitfall: Avoid Using Assertions to Check Preconditions 34
Static Checking Tools 34
Self-Test Exercises for Section 1.3 34
Chapter Summary 35
Solutions to Self-Test Exercises 36
5.6 A Generic Bag Class That Implements the Iterable Interface (Optional Section) 296
Programming Tip: Enhanced For-Loops for the Iterable Interface 297
Implementing a Bag of Objects Using a Linked List and an Iterator 298
Programming Tip: External Iterators Versus Internal Iterators 298
Summary of the Four Bag Implementations 299
Self-Test Exercises for Section 5.6 299
5.7 The Java Collection Interface and Map Interface (Optional Section) 300
The Collection Interface 300
The Map Interface and the TreeMap Class 300
The TreeMap Class 302
The Word Counting Program 305
Self-Test Exercises for Section 5.7 306
Chapter Summary 309
Solutions to Self-Test Exercises 310
Programming Projects 312
Author: Various
Language: English
Table of Contents
GRAHAM’S MAGAZINE.
THE SLAVER.
A TALE OF OUR OWN TIMES.
———
BY A SON OF THE LATE DR. JOHN D. GODMAN.
———
——
CHAPTER VI.
Jul. What villain, madam?
Lady Cap. That same villain, Romeo.
Jul. Villain and he are many miles asunder
God pardon him! I do, with all my heart:
And yet no man, like he, doth grieve my heart.
Romeo and Juliet.
When De Vere’s second picked him up, he was senseless; and his
shirt, stained with blood on the left breast, made him think he had
been shot through the heart. But the surgeon of the brig, who was
in attendance, examined him more closely, and found that he had
made a narrow escape; he was not mortally, but still dangerously
wounded; the ball had struck directly over the heart, but taking a
diagonal direction, it had passed out under his arm, without touching
the seat of life.
Carefully raising him, they carried him to the boat, and
supporting him on their knees, he was conveyed to his vessel, then
at anchor in the harbor.
De Vere had promised to dine at Don Manuel’s the day of the
duel; and the old gentleman, surprised at his absence—for he had
always been most punctual in keeping his appointments there—sent
a servant down to the brig to see if the captain was unwell.
The man came hurrying back with a long, exaggerated report of
the affair, and said that “Captain De Vere had been shot by a
notorious slave captain; and was dying, if not already dead.”
Alarmed at this information, the old gentleman went at once to
see De Vere; and finding he was only badly wounded, by the
consent of the physician, had him removed from the brig to his own
house.
So occupied was Don Velasquez with attending on the sick
captain, that for a day or two he neglected to call on “Brewster,”
though he was constantly endeavoring to think of some method by
which he could express the gratitude he felt for the preservation of
his beloved daughter; and he wondered why “Brewster” had not
again been to the house.
On the third day, however, his sense of duty not permitting him
longer to neglect one to whom he was under such great obligations,
he went out to see the captain of the schooner, and was surprised to
find the vessel had left the port.
Feeling vexed and mortified with himself that he had not more
promptly called upon “Brewster;” and believing his unceremonious
departure was occasioned by his own lack of proper attentions, he
returned home, and told his daughters of the disappointment he had
met.
Clara, whose pride was hurt, that one to whom the family were
indebted had been permitted thus to depart, with the obligation
unrequited, freely expressed her sorrow. Francisca said very little,
nothing more than was absolutely necessary, but felt far, far more
than either of them.
Pleased by the favorable impression Willis had made upon Clara,
and knowing that her father would naturally feel kindly toward one
who had rendered her such valuable service, she had been
permitting herself to indulge in pleasant visions of the future, in
which she saw every thing “couleur de rose,” and a happy
consummation to her heart’s passion.
These bright day-dreams were now all dispelled; and with a sad
heart she retired to the privacy of her chamber, to mourn over her
hard lot; for she thought “if Brewster had cared any thing for me, he
would at least have said, adieu, before leaving, perhaps for ever.”
De Vere, knowing the obligations Don Velasquez was under to
Willis, had, from a gentlemanly feeling, refrained from telling him
that Captain “Brewster, of the Portuguese navy,” was no other than
Willis, the notorious slaver, and the person who had so nearly killed
him; but when the old gentleman told him of “Brewster’s” sudden
departure, he apparently suffered so much from mortification and
self reproach, that De Vere thought it would relieve his mind to know
the true character of the person in whom he took so much interest;
he therefore told him, giving Willis, not his true character, but the
false one public report had fastened upon him.
Don Manuel listened to this narrative with varying emotions. At
first he could not credit it, so much was Willis’s appearance,
manners, and air distingué, at variance with his calling; but De Vere
insisted upon the correctness of his statement, and then the Don
was sorry, that one fitted to move in so much more elevated a
sphere, had no higher ambition or aim.
Upon the whole, however, Don Velasquez’s wounded self-esteem
was soothed; for though the obligation was in reality the same as
before, believing, now, that Willis’s mind must necessarily be sordid
and base, he thought money would liquidate the debt, and he would
still have an opportunity of acknowledging it. In the other case, with
a high-minded and gentlemanly man, as he had supposed him to be,
courtesies and attentions were the only return he could have made;
and to do this he had lost the opportunity.
Soothing his feelings, therefore, by resolving handsomely to
reward Willis, if ever he had the opportunity, he determined to give
himself no further trouble about the matter.
Clara, when she learned that “Brewster” had shot De Vere, and
was a negro trader, was loud in her reproaches; and calling him
many hard names, wondered how he had the impudence to enter
the house of a gentleman, and congratulated her sister upon her
lucky escape, after being in the power of such a wretch.
Poor Francisca, when she first heard the intelligence, felt as if her
heart had been shocked by an earthquake; for it seemed as if an
insurmountable barrier had now been raised between her and Willis.
True to her woman’s heart, she still loved him as much as ever,
and would not believe the reports to his detriment. She thought of
him but as she had known and seen him—kind, gentle, and noble;
and that if he was a slaver, it was not his own choice, but the result
of some dire necessity; and each time she heard De Vere or her
sister berate him, though it deeply wounded her, it only made the
remembrance of him more dear; for she felt the slanders were false.
Silently, however, she bore her sorrows; for, fearing to increase her
sister’s animosity, she never took the part of Willis when his name
was slurred.
The old duenna was the only one that stood out openly for the
defamed Willis; she stoutly declared “that Brewster, or Willis, slaver,
or man-of-war, she did not care which, he was the handsomest, the
most gentlemanly, and the kindest man she had ever seen; and if
ever she was in danger, she hoped he might be near to protect her;
and that it was a shame for them thus to run him down behind his
back, when he saved Señorita Francisca’s life, to say nothing of her
own.”
Balm it was to Francisca, to hear the old lady thus give utterance
to the thoughts she did not dare to speak; and in her daily orisons,
regularly did she supplicate the Virgin to protect the slaver’s captain,
and keep him in safety.
Captain De Vere’s wound, by assiduous nursing, did not prove
fatal; but his anxiety to be revenged on Willis was so great, that
before he was able to leave his couch, and against the advice and
entreaties of Don Manuel, Clara, and the physician, he insisted upon
joining his vessel, and going to sea, with the hope of capturing the
Maraposa on her return passage.
The result of his cruise has already been given in the preceding
chapter.
——
CHAPTER VII
Be not afraid!
’Tis but a pang, and then a thrill,
A fever fit, and then a chill,
And then an end of human ill;
For thou art dead.
Scott’s Lay of Louise.
The Scorpion and her prize had arrived safely in Havana. Willis,
heavily manacled, was brought on deck, where, joined by the small
remnant of his crew, amongst whom he was glad to discover the
face of Mateo, though its symmetry had been spoiled by a cutlas-
cut, extending from under his right eye to the left corner of his
mouth, entirely severing the end of his nose. The captain of the
Maraposa was kept a few moments waiting, and then, under a
strong guard, they were all carried to the Moro Castle, and lodged in
its dungeons, were left to await their trial.
Mateo and the rest of the men were put in a cell together, Willis,
for greater security, had been confined in a strong apartment alone.
It was the first time the slaver had ever been in prison, and the
close, dank air, the gloom, the high, dull, cold, stone walls, the
heavy fetters upon his limbs, the entire lack of any thing external to
distract his thoughts from his situation, all together, produced a
feeling of depression he had never known before.
Thus was he four days, with naught to while away the time but
his own thoughts, and they brought any thing but comfort to his
mind, for the past scenes of a misspent life were constantly
presenting themselves with the vividness of a panorama.
His early youth, when a good and gentle boy he had listened to
the kind admonitions of his excellent mother; then the loss of his
sweet parent, throwing him amongst selfish and careless relations;
his first steps in vice; then his desire to repent and reform; the cold
looks and want of sympathy with which he had been met; and
bitterly cursing the want of charity that had been so parsimonious of
kindness, when a few soothing words would have established him in
the road to rectitude, he looked at the darker deeds of the few last
years, and the end to which they would soon bring him.
Harassed by such painful reflections, it was a relief when the
jailor came to conduct him to trial, though he knew that with him
the road would be short from the tribunal to the gallows.
He felt that his fate was sealed; he had mortified De Vere so
much, by dismantling his vessel and killing so many of his men,
besides wounding him in the duel, that he knew the Englishman’s
influence would prevent his being treated with the least leniency,
and that the utmost penalty of the law would be exacted. He lacked
also that powerful friend, gold. Aware of the uncertain tenure one in
his profession had of life, he squandered the immense sums he
made as he got them, and he had not been allowed an opportunity
of obtaining aid from his associates.
It was with a mind conscious of the worst, and prepared to bear
it, that with a calm, determined countenance, and collected air, he
was confronted with his judges.
The indictment was read, and the presiding judge asked him if he
was “Guilty, or not guilty?”
“Guilty I am!” said Willis, “as who that hears me is not? but, that
I am more worthy of condemnation than even you, my judges, or
than the accuser, I deny! ’Tis true, I have been guilty of bringing
negroes from Africa to this island. But wherein am I thereby more
guilty than you? Do you not eagerly buy them as soon as landed;
and so hold out the temptation to bring them? ’Tis also true, that on
the high sea I did, with force and death, resist ‘her Britannic
Majesty’s vessel.’ Were moral right to prevail for once, her captain
would be in my situation; for by his intervention the slaves that I
would have brought here, to live in comfort to a good old age, will
now be condemned to hard and short lives, as apprentices, in Brazil.
But what avails my talking! My life, I know, is forfeited! and I will not
degrade myself by making useless efforts to save it.”
The counts in the indictment were all sustained. After a short
consultation, he was adjudged to die. And standing up to hear his
sentence, he found he was to be hung, the day after the morrow, to
the fore-yard of his own vessel. He then was carried back to his
dungeon.
After the captain had been sentenced, the rest of the crew were
brought up for trial; but being all men of little notoriety, and
pleading their necessity to obey the commands of Willis, and that
when they had joined the Maraposa they did not know she was a
slaver, they were all pardoned except Mateo, who was compelled to
pay a fine.
De Vere, after the trial, returned home exultingly; the man that
had caused him to be laughed at by the whole squadron, the one
who had nearly killed him, and again came within an ace of
capturing his brig, was about to be punished.
Clara was likewise glad to hear of Willis’s fate, for she hated him
for wounding her betrothed.
But Don Manuel learned the result of the trial with sadness; he
had tried to prevail upon De Vere not to prosecute, but the
Englishman said it was impossible; his sense of justice, his oath and
honor as an officer, all, he contended, compelled him to have the
law enforced; he had even made an effort to influence the court, but
found De Vere’s influence governed them all; he had not, however,
given up all hope yet.
Well was it for the secret of Francisca’s heart that the sentence of
Willis was conveyed to her in her own chamber, by the faithful
duenna, for as soon as she heard the awful news she sunk senseless
on the floor; swoon succeeded swoon for some time, but recovering,
in a degree, her composure, her eye brightened and her cheek
flushed, as if some happy idea had flashed across her mind, and
leaving the room she sought her father.
It was the night after the day of the trial, the bells of the many
churches had just ceased chiming ten, when the silence that reigned
in the slaver’s cell was broken by the sound of a key grating in the
lock of his door.
Surprised at having a visiter at so unusual an hour, Willis turned
to see why he was disturbed, and was astonished to discover, as the
door opened, by the light in the hands of the jailor, who remained in
the passage, a female figure, closely enveloped in the folds of a
large mantilla, glide into his dungeon. When within a few feet of
Willis, the lady paused, and, save the convulsive motion of her
breast, stood for a moment motionless. Then, slowly dropping the
mantilla from about her face, she revealed to the startled gaze of
the prisoner the features of Francisca, not as he had seen them, but
pale as death, and thin, as if she had lately been very ill.
Willis was about to speak, but raising her finger as a sign for him
to be silent, she said —
“Time is precious, Captain Willis, waste it not in inquiries or
conjectures of the cause of my being here, but believe that I am
deeply grateful for the life I owe you, and am desirous of repaying it
in kind. Every exertion has been made without success by my father
to procure your pardon, but my efforts have been more blessed. In
two hours the turnkey, who has been bribed, will let you out;
proceed to the nearest quay, where you will find all that is left of
your crew, waiting for you in a boat; take them to your schooner,
which is at anchor in the same place she was when you were
brought here; the few men in charge of her have also been bought;
and then to make your way out safely will have to depend upon
yourself.”
Again Willis endeavored to speak, and express his thanks, but
Francisca motioned him to hush.
“One moment more, and I must be gone. In this package,” she
handed him a small bundle, apparently of paper, “you will find that
which will be useful to you, if you get to sea. And praying that the
blessed Virgin will protect you, I wish you God speed.”
She turned, and was going, but Willis seized her hand for an
instant, and imprinting upon it a kiss, said, in a voice tremulous with
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.
ebookluna.com