ebook img

Data Abstraction & Problem Solving with Java: Walls and Mirrors PDF

942 Pages·2010·92.801 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Data Abstraction & Problem Solving with Java: Walls and Mirrors

Qual iitsy shit I'll look for a better one Data Abstracti & Problem Solvin g with ' 3rEdd itWiaolnl& s M irror$ , JANJEP.TR ICHIAF RRDA MN.KC ARRA-.N�.O -· ·�tr---·. _. !'" ·- � '• '· •. ..., · l. -' 1 • .1·� Summary of Java Statements assign111e11f l'llrial>le exprc•ssio11; a co111pou11d { Sltlll!IIIC'l/1 I SI() l<.'11/t'I//~ S/(l/1!1111!11/,. } if if ( 1!.l'pl"<'.~.)'iOII) Sllll<!lll('J// if-else if ce xpression) Sltllt>lll<!/1/ I else s1a1e111e111 3 switc/r switch 1e:o:pressio11) { case COIIS/(ll//1: S/(l//?Jll(!ll/1 break; case co11s11111I.,: s1a1e111e111. break; default: state111e111 } for for (i11itiali:e; test; update) staten1ent for ( variable:collectio11) state111e111 for { variable:array) staleme111 while while (expression) state111e11t do do statement while (expression); I ,I I :-, . r"·• . . .. - Data Abstra . . ' • . . . ' ~ & Problem S with JA'Vi ,VALLS AND . .. MIRRORS • I I ·- •, Data Abstra · ·, ' & Problem S • WALLS AND ! MIRRORS •f I :' i .. , 3"" Edition Ja,,et ]. Prich11,rd • Brr,m Univcersity I ' ' t . : Opcr,uion.~ Srcd.,H~: Li'-1 Mcl)t"' dl Editori>I Oir«cor: Mar<io Horron Tt~M IK•,.it-ncr: S.m~.tr.1 Rigm:y Editor-in-Chief. ~.lich•ol Hir,<h Cn:-.uh-c Din."\·wr: J.wn~ Conu.· Editori>I A..sis1:1nt: Srcph.rnic Sellinger Ccl\'Cr l)c,igner. Su1,.11mc ))u.l, M,rkding ~bnagcr. Ye2a,1 Al•y•n C:m,:r ln1.1ge: G..-ny 1111,,g<.-s/Sic,·c \VJII M>Ilering ~t•nt: Kathryn n ·rr.uni full•&·r,i\'.'c V"·11Jor: GEX PuN~hin~ St·r,·h'.'l'' Vi« Prnidcnr. Produccio,i: Vi11,-c O'Brien srr l'rintcr/Cm...-r Primcr/ l!indcr; Courier M.,,oging Editor. Jeff Holcomb S<nior I'rodu,-uon l'n,jc,.'t ~lan.,g..-r: M,,rilp1 Li<>)~I .Stoushton Credit$ and :u:-knowt'-.Jttnl.:.·n~ borrowc.~l from oth...-r M)Uf\'.'('~ .1nd n:.·pnKlm:cd. wirh pt·nni~iun. in thi, H.·,t• book appe;ir on upproprfat'-' P.1$.C: "ithin t~\t. Copyright C) 2011, 2006, 2004 1',,rson Educ,tion, Inc., publishing•• A,t,lil<>n·\\'c,kr, ,-\II right, n:-.cr,,,1. ~lanufacrun:d in the UnitOO St.m,:s ofAm,"ri1.\l, This publkJtion is pn>tt.Xh.·d br (",<)prri~n. Jmt 1x-rm1,,-1on should be obuincd &om th~ publisher prior to any prohibited rcproduc1io.n, ~t()r.i.g,-in.\ rt·rrit"\,.'1 ,~-,h.·m. or cransmission in .my form or by :in)' m~J.ns. eli:..:1ronic ~ mt.'"hlnk-..1. photoc<>p)'lng.. rccordini, or lik1,,.,, i~ ·1.. . obtain pcrnlission(s) to use m.1tcriaJ from this work.1>lc.1sc ~ubmit ., ,,·rinco n:qm:llt lo l\·.lr.ou f:J\l"'Jli-.,n. In<., Pcrmissio,1$ lx1»ftnlCt\f, 501 lloylstQn Sitt'<<, Snitc 900. Bosrc»i. MM.S.lchuscn, 02116. Mani-oft he dcsign,ri<>1lS b)' m;i,mfacrurcrs Jnd sdkr ro disting\lish 1h<ir pn,ducts Jre cbimcd,:, trJ<kni,u-k,. Where m<>SC dcsign,tions oppcar in this book, anJ cite publishc.r w•s .,w,,rc of,, rr,,knurk dJilll, 1hc ,k,ig,u tions ha,·c b«n printed in initi.11 ,,o,ps or .ill ~~ps. Ubrary of Congress C:naloging·in•Publication D•m is available upon ~\IC$t 10 9 8 7 6 5 4 3 2 I-CRS-14 13 12 II 10 - • Addison-Wesley is an Imprint of - PEARSON ISBN JO; 0-13-212230-8 ISBN 13:978,0-13-212230-6 Brief Contents PART ONE Problem-Solving Techniques 1 1 Review of Java Fundamentals 3 2 Principles of Programming and Software Engineering 81 3 Recursion: The Mirrors 137 4 Data Abstraction: The wans 197 5 Linked Lists 241 PART TWO Problem Solving with Abstract Data Types 313 6 Recursion as a Problem-Solving Technique 315 7 Stacks 351 8 Queues 409 9 Advanced Java Topics 455 10 Algorithm Efficiency and Sorting 505 11 Trees 561 12 Tables and Priority Queues 643 13 Advanced Implementations of Tables 699 14 Graphs 777 15 External Methods 823 APPENDICES A A Comparison of Java to C++ 863 B Unicode Character Codes (ASCII Subset) 867 C Java Resources 868 D Mathematical Induction 870 Glossary 877 Self-Test Answers 897 Index 921 Contents Preface xv Chapter Dependency Chart xviii PART ONE Problem-Solving Technique• 1 1 a Review of Java Fundamental• 1.1 Language Basics 4 Comments 4 Identifiers and Keywords 4 Variables 4 Primitive Data Types 5 References 6 literal Constants 6 Named Constants 7 Assignments and Expressions 8 Arrays 11 1.2 Selection Statements 14 The if Statement 15 The switch Statement 16 1.3 Iteration Statements 17 The while Statement 17 The for Statement 18 The do Statement 21 1.4 Program Strue1ure 21 Packages 22 Classes 23 Data Relds 24 Methods 26 How to Access Members of an Object 30 Class Inheritance 30 . . . ~· . •. ;i:t.~ .t•.~\~~- CQ111en1s 32 useful Java crasses 1.5 The Object Class 32 The Array Class 34 String Classes 35 Java Exceptions 40 1.6 Catctting Exceptions 40 Throwing Exceptions 4 7 1.7 Text Input and Output 49 Input 49 Output 51 The console Class 54 1.8 File Input and Output 56 Text Files 58 Objecl Serialization 66 summa,y 69 C&urions 72 Self• Tes1 Exercises 72 Exercisas 73 Programming PrOblemS 78 2 Prtnolpl- of Programming and Softwa.-. Engineering 81 2.1 Problem SoMng and Software Engineering 82 Whal Is Problem Solving? 82 The Ufa Cycle of Software 83 What IS a GOOd Solution? 93 2.2 Achieving an Object-Oriented Design 95 Abstraction and lnfoonation Hiding 96 Objec1-0riented Design 98 Functional Decomposition 100 General Design Guidelines 101 Modeling Object-Oriented Designs Using UML 102 Advantages of an Object-Oriented Approach 106 2 .3 A Summa,y of Key Issues in Programming 107 Modularity 107 Modifiability 109 Ease of Use 111 Fail-SSfe Progranvning 112 Style 118 Debugging 122 Summary 125 Cautions 126 Self-Test Exercises 126 Exercises 127 Programming Problems 132 3 Racura1on1 The Mlrr'Ow"a 137 3.1 Recursive Solutions 138 A Recursive Valued Method: The Factorial of n 141 A Recursive void Method: Writing a String Backward 148 Col\tents Ix 3 .2 Counting Things 159 Mult1plymg Rabbits (The Ftbonacc, Sequence) 159 Organizing a Parade 161 Mr. Spock's Ddemma (Choosing I< out of n Things) 164 3 .3 Searching an Nray 166 F,noing the Largest Item 1n an Array 167 Buia<)- Search t68 Finding the~•• Smallest Uem 1n an Array 172 3 .4 Organizing Data 176 The To we<s of Hano, 176 3.5 Recursion and Efficiency 180 S.1r,n,a~~ ,~:-- CJUIKWJ..< 1e; Seit-Test Exercises 188 E,erc Fr,,gr~mm11,g Problems 195 s.?S ?&"I 4 Data AbatraotJon: The Walla 197 4.1 Abstract Data Types 198 4 .2 Specifying ADTs 203 The AOT L;st 204 The .\OT Soiled List 209 Oesign,rig an ADT 211 AlCOmS ,Optional) 215 4 .3 Implementing AOTs 218 Java Classes Revisited 219 Java Interfaces 221 Java Packages 224 An Alray-Based Implementation of the ADT List 226 Summal)I 233 Cautions 233 Self, Test Exercises 234 Exerc,ses 235 Programming Problems 238 5 Unkec:I Uate 241 5 .1 Preliminaries 242 Ob1ect References 242 Resizeable Arrays 248 Reference-Based Linked Lists 249 5 .2 Programming with Linked LiSIS 253 Displaying lhe Contents of a Linked List 253 Delebng a Spec,fted Node ftom a Linked list 255 Inserting a Node into a Specified Position or a linked List 258 A Reletence-Based Implementation of the AOT Lisi 264 COmpanng Alray-Based and Refetence-Based lmplementa1ions 268 Passing a Linked Ltst to a MelllOd 271 Processing linked Lists Recursively 271 .. X Contents 5.3 variations of tile Linked List 277 2n Tail References Circular Linked Lists 278 Dummy Head Nodes 280 Doubly Linked Lists 280 5 ,4 Application: Maintaining an Inventory 284 5.5 The Java Collections Framework 290 Generics 291 Iterators 292 The Java Collection's Framework Llst Interface 295 Summary 298 Cautoos 300 Self-Test Exercises 301 Exercises 303 Programming Problems 301 PART TWO Problem Solvlng with Abstract Data Type• 313 8 Aeouralon aa a Problem•8olvlng Technique 315 6.1 Backtracking 316 The Eight Queens Problem 316 6.2 Defining Languages 321 The Basics of Grammars 322 Two Simple Languages 323 Algebraic Expressions 326 6.3 The Relationship Between Recursion and Mathematical Induction 336 The Correctness of the Recursive Factorial Method 336 The Cost ol Towers of Hanoi 337 Summary 339 Cautions 339 Self-Test Exercises 340 Exercises 340 Programming Problems 344 7 9tll0ka 381 7 .1 The Abs1ract Oa1a lype Stack 352 Developing an ADT During the Design of a Solution 352 7 .2 Simple Applications ol the AOT Stack 358 Checking tor Balanced Braces 358 Recognizing Strings in a Language 362 7.3 Implementations o1 the ADT Stack 363 An Array-Based Implementation of the ADT Stack 365 A Reference-Based Implementation of the AOT Stack 367 An Implementation That Uses the ADT List 369 Comparing Implementations 371 The Java Collections Framework Class stack 371 7 .4 Application: Algebraic Expressions 373 Evaluating Postfix Expressions 373 Converting Infix Expressions to Equivalent Postfix Expressions 375

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.