Complete Download (eBook PDF) Data Structures and Other Objects Using Java 4th Edition PDF All Chapters
Complete Download (eBook PDF) Data Structures and Other Objects Using Java 4th Edition PDF All Chapters
com
https://ebookluna.com/product/ebook-pdf-data-structures-and-
other-objects-using-java-4th-edition/
OR CLICK HERE
DOWLOAD NOW
https://ebookluna.com/product/ebook-pdf-data-structures-and-problem-
solving-using-java-4th-edition/
ebookluna.com
https://ebookluna.com/product/ebook-pdf-data-structures-and-
abstractions-with-java-4th-edition/
ebookluna.com
https://ebookluna.com/product/ebook-pdf-data-structures-and-
abstractions-with-java-4th-global-edition/
ebookluna.com
https://ebookluna.com/product/ebook-pdf-starting-out-with-java-from-
control-structures-through-data-structures-4th-edition/
ebookluna.com
Data Structures and Abstractions with Java 5th Edition
(eBook PDF)
https://ebookluna.com/product/data-structures-and-abstractions-with-
java-5th-edition-ebook-pdf/
ebookluna.com
https://ebookluna.com/product/ebook-pdf-starting-out-with-java-from-
control-structures-through-objects-7th-edition/
ebookluna.com
https://ebookluna.com/product/ebook-pdf-starting-out-with-java-from-
control-structures-through-data-structures-3rd-edition/
ebookluna.com
https://ebookluna.com/product/ebook-pdf-introduction-to-java-
programming-and-data-structures-comprehensive-version-11/
ebookluna.com
https://ebookluna.com/product/ebook-pdf-java-foundations-introduction-
to-program-design-and-data-structures-5th-edition/
ebookluna.com
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
El Amor y la Queja
Palomita blanca,
remonta tu vuelo,
y al bien que yo adoro
dile que me muero...
También Martín Fierro colabora en esta propensión a la queja dulce y al
dolor de la ausencia. Azuzado por la justicia, pobre y errante, necesita poner
su memoria en la dama de sus pensamientos y canta:
En la orilla de un arroyo
solitario lo pasaba,
en mil cosas cavilaba,
y a una güelta repentina
se me hacía ver a mi china
o escuchar que me llamaba.
P OR entre los versos del Martín Fierro brilla con frecuencia el cuchillo
de nuestro gaucho errante, y con esa arma compañera se consuman
hazañas increíbles, como el resistir en pleno campo abierto a un pelotón
de soldados policiales.
Viajando una vez por la provincia de Entre Ríos, cuyo paisaje algo seco
y surcado de pelados oteros recuerda bastante al campo de Castilla,
sorprendí un hombre a caballo, verdadera imagen del romancesco tipo del
gaucho. Ya no vestía chiripá, pero en su defecto portaba unos anchísimos
calzones bombachos, y sobre la erguida cabeza llevaba un sombrero
afieltrado, con masculino y coquetón talante. Al girar de espaldas, mostró
en el cinto, por la parte de los riñones, cruzado un largo cuchillo de punta
sutil. Mientras el tren arrancaba con enfática carrera, el hombre del caballo
y del cuchillo se internó serenamente en la llanura, bien tieso en su silla
nacional, impasible y orgulloso, como una página del pasado que se vuelve
y huye...
He nombrado el cuchillo, y la palabra no es justa del todo. El cuchillo o
facón gauchesco era más bien una espada. Sus dimensiones tenían una
prudente medida, y si era demasiado largo para cuchillo, quedaba algo corto
para llegar a espada. El gaucho no podía llevar una espada al cinto, como
un soldado de caballería; su manera violenta y continua de cabalgar, y su
deseo de no separarse nunca del arma fiel, le obligó a cortar la espada del
caballero o del hidalgo. La cruzó en la cintura, la sujetó a su cuerpo, y así
logró convertirla en algo indivisible con su persona.
Al referirme al cuchillo del gaucho hablo en pretérito, porque el arma
nacional de los ríoplatenses va desapareciendo, y sólo es usado tal vez en
las comarcas desviadas. El europeo ha traído el uso del revólver, arma fácil
y expedita que no requiere una maniobra tan complicada como aquel acero
filoso, únicamente eficaz cuando la mano, la vista y el corazón del gaucho
lo esgrimía en los imponentes entreveros[28].
Tampoco podía el europeo desenvolverse en el seno de la Naturaleza,
desafiarla y vencerla como el gaucho. Este hombre primitivo contaba
solamente con su voluntad y sus iniciativas. Situado en mitad del desierto,
se buscaba un camino, se orientaba por las huellas sutiles de la luz o del
color y sabor de las hierbas, y nada quedaba para él sin expresión, desde el
vuelo de las aves hasta el mugido de las bestias errabundas. Poco debía
contar con la justicia ni con los poderes constituidos; en último caso fiaba a
su acero la defensa de su familia y de su prestigio personal. El europeo,
debilitado por la civilización, procura reconciliarse con la Naturaleza, y al
reñir contra ella no marcha de frente, sino que la soslaya, y pone por medio
la mecánica de la industria y la otra mecánica de las leyes colectivas.
Un pueblo entero, libre y robusto, usaba hasta ayer mismo la espada del
caballero o del hidalgo, como hace dos o tres siglos la usaban en Europa las
gentes nobles. No se olvide que la espada significa libertad, aunque las
mentes un poco aturdidas por la democracia tomen esto por una blasfemia.
La espada no ha sido nunca negocio de esclavos, porque implica el sentido
de la mayor independencia personal. La espada hace sagrado el concepto de
la personalidad, y un hombre que la lleva al cinto está significando a todos
los otros hombres que su independencia personal comienza desde la misma
punta de su espada. Los caballeros del siglo XVI, llevando todos el signo
acerado y mortífero de la libertad, por imposición natural interponían entre
ellos la virtud más deseable y democrática: el respeto mutuo.
Así Pizarro, detenido en la isla del Gallo por las suspicacias de algunos
compañeros, cuando quiso arrastrar su gente a la gran aventura de
conquistar el Perú no osó proferir gritos y órdenes de mando, sino que sacó
la espada, rayó la tierra con un brusco ademán y empezó: ¡Señores...!
Aquellos hidalgos trajeron la espada a la llanura ríoplatense, y el gaucho,
pobre y errante como su progenitor, lleno de sus mismos prejuicios, reacio a
la industria, atento al honor y a la libertad más que al ahorro, fué un
testamentario y un continuador en América de la tradición castellana.
Cuando en la tierra originaria no quedaron hidalgos de espada al cinto, en la
Pampa vivía el gaucho una vida hidalguesca, con su caballo y su daga, su
puntillo de honor y su aventura.
No; no era para todos el manejo de la daga gauchesca. Nada tan
complicado como su esgrima, ni nada tan terrible como un hombre de
aquellos cuando enrollaba al brazo el poncho, se quitaba las grandes
espuelas y hacía brillar la hoja del cuchillo. A veces las pendencias duraban
mucho tiempo, y el sudor bañaba los rostros que la ira hacía enrojecer. Los
circunstantes formaban en círculo, y a nadie se le ocurría que podía
intervenir en aquel torneo legal y honroso. Juntos los pies de ambos
luchadores, casi abrazados los dos, hacían largo tiempo culebrear los
aceros, parándose los tajos con el poncho, ladeándose, evitándose como
ágiles reptiles. Un chirle en la cara era golpe muy apreciado, y a veces
bastaba la herida del rostro para lavar una ofensa. Pero los verdaderamente
bravos no se contentaban con tan poco. Martín Fierro era hábil en hundir el
cuchillo hasta la empuñadura.
Yo tenía un facón con S[29]
que era de lima de acero;
le hice un tiro, lo quitó
y vino ciego el moreno.
Y ya me hizo relumbrar
por los ojos el cuchillo,
alcanzando por la punta
a cortarme en un carrillo.
Hazañas y Entreveros
A la llegada metió
el pingo hasta la ramada,
y yo sin decirle nada
me quedé en el mostrador.
Y ya salimos trenzaos,
porque el hombre no era lerdo;
mas como el tino no pierdo
y soy medio ligerón,
le dejé mostrando el sebo
de un revés con el facón.
Pero estas son riñas de uno contra uno, de forma caballeresca popular y
muy semejantes a las riñas de otros países. Donde se prueba el valor del
gaucho y la potencia de su cuchillo y de su esgrima, es en los entreveros de
uno contra muchos, o en la pelea contra un indio armado de boleadoras.
Me encontraba, como digo,
en aquella soledá,
entre tanta oscuridá
echando al viento mis quejas,
cuando el grito del chajá[30]
me hizo parar[31] las orejas.
Al punto me santigüé
y eché de giñebra un taco;
lo mesmito que el mataco[33]
me arrollé con el porrón.
“Si han de darme pa tabaco,
dije, esta es güena ocasión.”
Y ya vide el fogonazo
de un tiro de carabina;
mas quiso la suerte indina
de aquel maula, que me errase,
y ahí no más lo levantase
lo mesmo que una sardina...
El más engolosinao
se me apió con un hachazo;
se lo quité con el brazo,
de no, me mata los piojos;
y antes de que diera un paso
le eché tierra en los dos ojos.
Y mientras se sacudía
refregándose la vista,
yo me le fuí como lista
y ahí no más me le afirmé,
diciéndole: “Dios te asista”,
y de un revés lo voltié...
En fin, la feroz pelea de uno contra tantos acaba, o se precipita al
desenlace, cuando uno de los soldados, el sargento Cruz, se pasa al campo
de Martín Fierro, gritando aquella voz quijotesca:
...¡Cruz no consiente
que se cometa el delito
de matar ansí un valiente!
C AP Í T UL O VI I I
Los Indios