| Preface |
|
v | |
| Chapter Dependency Chart |
|
vii | |
| PART I Problem-Solving Techniques |
|
1 | (278) |
|
CHAPTER 1 Principles of Programming and Software Engineering |
|
|
2 | (51) |
|
1.1 Problem Solving and Software Engineering |
|
|
3 | (12) |
|
|
|
3 | (1) |
|
The Life Cycle of Software |
|
|
4 | (9) |
|
|
|
13 | (2) |
|
1.2 Achieving a Modular Design |
|
|
15 | (11) |
|
Abstraction and Information Hiding |
|
|
15 | (2) |
|
|
|
17 | (3) |
|
|
|
20 | (1) |
|
General Design Guidelines |
|
|
21 | (1) |
|
Modeling Object-Oriented Designs Using UML |
|
|
21 | (4) |
|
Advantages of an Object-Oriented Approach |
|
|
25 | (1) |
|
1.3 A Summary of Key Issues in Programming |
|
|
26 | (20) |
|
|
|
27 | (1) |
|
|
|
28 | (2) |
|
|
|
30 | (1) |
|
|
|
31 | (6) |
|
|
|
37 | (7) |
|
|
|
44 | (2) |
|
|
|
46 | (1) |
|
|
|
47 | (1) |
|
|
|
48 | (1) |
|
|
|
48 | (2) |
|
|
|
50 | (3) |
|
CHAPTER 2 Recursion: The Mirrors |
|
|
53 | (60) |
|
|
|
54 | (21) |
|
A Recursive Valued Function: The Factorial of n |
|
|
57 | (6) |
|
A Recursive void Function: Writing a String Backward |
|
|
63 | (12) |
|
|
|
75 | (8) |
|
Multiplying Rabbits (The Fibonacci Sequence) |
|
|
75 | (3) |
|
|
|
78 | (2) |
|
Mr. Spock's Dilemma (Choosing k Out of n Things) |
|
|
80 | (3) |
|
|
|
83 | (9) |
|
Finding the Largest Item in an Array |
|
|
83 | (1) |
|
|
|
84 | (4) |
|
Finding the k th Smallest Item of an Array |
|
|
88 | (4) |
|
|
|
92 | (5) |
|
|
|
92 | (5) |
|
2.5 Recursion and Efficiency |
|
|
97 | (5) |
|
|
|
102 | (1) |
|
|
|
103 | (1) |
|
|
|
104 | (1) |
|
|
|
104 | (8) |
|
|
|
112 | (1) |
|
CHAPTER 3 Data Abstraction: The Walls |
|
|
113 | (51) |
|
|
|
114 | (5) |
|
|
|
119 | (14) |
|
|
|
119 | (5) |
|
|
|
124 | (2) |
|
|
|
126 | (5) |
|
|
|
131 | (2) |
|
|
|
133 | (23) |
|
|
|
135 | (9) |
|
|
|
144 | (2) |
|
An Array-Based Implementation of the ADT List |
|
|
146 | (6) |
|
|
|
152 | (2) |
|
An Implementation of the ADT List Using Exceptions |
|
|
154 | (2) |
|
|
|
156 | (1) |
|
|
|
157 | (1) |
|
|
|
158 | (1) |
|
|
|
159 | (3) |
|
|
|
162 | (2) |
|
|
|
164 | (78) |
|
|
|
165 | (12) |
|
|
|
166 | (6) |
|
Dynamic Allocation of Arrays |
|
|
172 | (3) |
|
Pointer-Based Linked Lists |
|
|
175 | (2) |
|
4.2 Programming with Linked Lists |
|
|
177 | (32) |
|
Displaying the Contents of a Linked List |
|
|
178 | (1) |
|
Deleting a Specified Node from a Linked List |
|
|
179 | (3) |
|
Inserting a Node into a Specified Position of a Linked List |
|
|
182 | (6) |
|
A Pointer-Based Implementation of the ADT List |
|
|
188 | (8) |
|
Comparing Array-Based and Pointer-Based Implementations |
|
|
196 | (2) |
|
Saving and Restoring a Linked List by Using a File |
|
|
198 | (4) |
|
Passing a Linked List to a Function |
|
|
202 | (1) |
|
Processing Linked Lists Recursively |
|
|
203 | (5) |
|
Objects as Linked List Data |
|
|
208 | (1) |
|
4.3 Variations of the Linked List |
|
|
209 | (6) |
|
|
|
209 | (2) |
|
|
|
211 | (1) |
|
|
|
211 | (4) |
|
4.4 Application: Maintaining an Inventory |
|
|
215 | (6) |
|
4.5 The C++ Standard Template Library |
|
|
221 | (7) |
|
|
|
221 | (1) |
|
|
|
222 | (2) |
|
The Standard Template Library Class list |
|
|
224 | (4) |
|
|
|
228 | (2) |
|
|
|
230 | (2) |
|
|
|
232 | (3) |
|
|
|
235 | (3) |
|
|
|
238 | (4) |
|
CHAPTER 5 Recursion as a Problem-Solving Technique |
|
|
242 | (37) |
|
|
|
243 | (7) |
|
|
|
243 | (2) |
|
Implementing Eight Queens Using the STL Class vector |
|
|
245 | (5) |
|
|
|
250 | (15) |
|
|
|
251 | (1) |
|
|
|
252 | (3) |
|
|
|
255 | (10) |
|
5.3 The Relationship Between Recursion and Mathematical Induction |
|
|
265 | (3) |
|
The Correctness of the Recursive Factorial Function |
|
|
265 | (1) |
|
The Cost of Towers of Hanoi |
|
|
266 | (2) |
|
|
|
268 | (1) |
|
|
|
269 | (1) |
|
|
|
269 | (1) |
|
|
|
269 | (4) |
|
|
|
273 | (6) |
| PART II Problem Solving with Abstract Data Types |
|
279 | (534) |
|
|
|
280 | (58) |
|
6.1 The Abstract Data Type Stack |
|
|
281 | (6) |
|
Developing an ADT During the Design of a Solution |
|
|
281 | (6) |
|
6.2 Simple Applications of the ADT Stack |
|
|
287 | (4) |
|
Checking for Balanced Braces |
|
|
287 | (3) |
|
Recognizing Strings in a Language |
|
|
290 | (1) |
|
6.3 Implementations of the ADT Stack |
|
|
291 | (14) |
|
An Array-Based Implementation of the ADT Stack |
|
|
292 | (4) |
|
A Pointer-Based Implementation of the ADT Stack |
|
|
296 | (3) |
|
An Implementation That Uses the ADT List |
|
|
299 | (4) |
|
Comparing Implementations |
|
|
303 | (1) |
|
|
|
303 | (2) |
|
6.4 Application: Algebraic Expressions |
|
|
305 | (6) |
|
Evaluating Postfix Expressions |
|
|
306 | (1) |
|
Converting Infix Expressions to Equivalent Postfix Expressions |
|
|
307 | (4) |
|
6.5 Application: A Search Problem |
|
|
311 | (12) |
|
A Nonrecursive Solution That Uses a Stack |
|
|
312 | (8) |
|
|
|
320 | (3) |
|
6.6 The Relationship Between Stacks and Recursion |
|
|
323 | (2) |
|
|
|
325 | (1) |
|
|
|
326 | (1) |
|
|
|
326 | (1) |
|
|
|
327 | (4) |
|
|
|
331 | (7) |
|
|
|
338 | (46) |
|
7.1 The Abstract Data Type Queue |
|
|
339 | (2) |
|
7.2 Simple Applications of the ADT Queue |
|
|
341 | (3) |
|
Reading a String of Characters |
|
|
342 | (1) |
|
|
|
343 | (1) |
|
7.3 Implementations of the ADT Queue |
|
|
344 | (19) |
|
A Pointer-Based Implementation |
|
|
344 | (6) |
|
An Array-Based Implementation |
|
|
350 | (6) |
|
An Implementation That Uses the ADT List |
|
|
356 | (3) |
|
|
|
359 | (3) |
|
Comparing Implementations |
|
|
362 | (1) |
|
7.4 A Summary of Position-Oriented ADTs |
|
|
363 | (1) |
|
7.5 Application: Simulation |
|
|
364 | (10) |
|
|
|
374 | (1) |
|
|
|
375 | (1) |
|
|
|
375 | (1) |
|
|
|
376 | (4) |
|
|
|
380 | (4) |
|
CHAPTER 8 Advanced C++ Topics |
|
|
384 | (59) |
|
8.1 Inheritance Revisited |
|
|
385 | (11) |
|
Public, Private, and Protected Inheritance |
|
|
391 | (2) |
|
Is-a , Has-a , and As-a Relationships |
|
|
393 | (3) |
|
8.2 Virtual Functions and Late Binding |
|
|
396 | (10) |
|
|
|
401 | (5) |
|
|
|
406 | (2) |
|
8.4 The ADTs List and Sorted List Revisited |
|
|
408 | (8) |
|
Implementations of the ADT Sorted List That Use the ADT List |
|
|
411 | (5) |
|
|
|
416 | (6) |
|
|
|
422 | (5) |
|
|
|
427 | (6) |
|
Implementing the ADT List Using Iterators |
|
|
429 | (4) |
|
|
|
433 | (1) |
|
|
|
434 | (1) |
|
|
|
435 | (1) |
|
|
|
436 | (4) |
|
|
|
440 | (3) |
|
CHAPTER 9 Algorithm Efficiency and Sorting |
|
|
443 | (56) |
|
9.1 Measuring the Efficiency of Algorithms |
|
|
444 | (12) |
|
The Execution Time of Algorithms |
|
|
445 | (2) |
|
|
|
447 | (1) |
|
Order-of-Magnitude Analysis and Big O Notation |
|
|
448 | (5) |
|
|
|
453 | (2) |
|
The Efficiency of Searching Algorithms |
|
|
455 | (1) |
|
9.2 Sorting Algorithms and Their Efficiency |
|
|
456 | (34) |
|
|
|
457 | (4) |
|
|
|
461 | (2) |
|
|
|
463 | (2) |
|
|
|
465 | (6) |
|
|
|
471 | (11) |
|
|
|
482 | (3) |
|
A Comparison of Sorting Algorithms |
|
|
485 | (1) |
|
The STL Sorting Algorithms |
|
|
485 | (5) |
|
|
|
490 | (1) |
|
|
|
491 | (1) |
|
|
|
492 | (1) |
|
|
|
493 | (3) |
|
|
|
496 | (3) |
|
|
|
499 | (90) |
|
|
|
501 | (6) |
|
|
|
507 | (28) |
|
Traversals of a Binary Tree |
|
|
512 | (4) |
|
Possible Representations of a Binary Tree |
|
|
516 | (4) |
|
A Pointer-Based Implementation of the ADT Binary Tree |
|
|
520 | (15) |
|
10.3 The ADT Binary Search Tree |
|
|
535 | (40) |
|
Algorithms for the ADT Binary Search Tree Operations |
|
|
540 | (15) |
|
A Pointer-Based Implementation of the ADT Binary Search Tree |
|
|
555 | (8) |
|
The Efficiency of Binary Search Tree Operations |
|
|
563 | (5) |
|
|
|
568 | (1) |
|
Saving a Binary Search Tree in a File |
|
|
568 | (3) |
|
The STL Search Algorithms |
|
|
571 | (4) |
|
|
|
575 | (1) |
|
|
|
576 | (1) |
|
|
|
577 | (1) |
|
|
|
577 | (2) |
|
|
|
579 | (7) |
|
|
|
586 | (3) |
|
CHAPTER 11 Tables and Priority Queues |
|
|
589 | (64) |
|
|
|
590 | (21) |
|
Selecting an Implementation |
|
|
596 | (8) |
|
A Sorted Array-Based Implementation of the ADT Table |
|
|
604 | (4) |
|
A Binary Search Tree Implementation of the ADT Table |
|
|
608 | (3) |
|
11.2 The ADT Priority Queue: A Variation of the ADT Table |
|
|
611 | (20) |
|
|
|
615 | (10) |
|
A Heap Implementation of the ADT Priority Queue |
|
|
625 | (3) |
|
|
|
628 | (3) |
|
11.3 Tables and Priority Queues in the Standard Template Library |
|
|
631 | (13) |
|
The STL Associative Containers |
|
|
631 | (9) |
|
The STL priority_queue Class and Heap Algorithms |
|
|
640 | (4) |
|
|
|
644 | (1) |
|
|
|
645 | (1) |
|
|
|
645 | (1) |
|
|
|
646 | (4) |
|
|
|
650 | (3) |
|
CHAPTER 12 Advanced Implementations of Tables |
|
|
653 | (74) |
|
12.1 Balanced Search Trees |
|
|
654 | (37) |
|
|
|
655 | (20) |
|
|
|
675 | (7) |
|
|
|
682 | (3) |
|
|
|
685 | (6) |
|
|
|
691 | (23) |
|
|
|
695 | (2) |
|
|
|
697 | (9) |
|
The Efficiency of Hashing |
|
|
706 | (3) |
|
What Constitutes a Good Hash Function? |
|
|
709 | (2) |
|
Table Traversal: An Inefficient Operation Under Hashing |
|
|
711 | (1) |
|
Implementing a HashMap Class Using the STL |
|
|
712 | (2) |
|
12.3 Data with Multiple Organizations |
|
|
714 | (5) |
|
|
|
719 | (2) |
|
|
|
721 | (1) |
|
|
|
721 | (1) |
|
|
|
722 | (3) |
|
|
|
725 | (2) |
|
|
|
727 | (44) |
|
|
|
728 | (3) |
|
|
|
731 | (7) |
|
|
|
732 | (3) |
|
Implementing a Graph Class Using the STL |
|
|
735 | (3) |
|
|
|
738 | (7) |
|
|
|
739 | (3) |
|
|
|
742 | (1) |
|
Implementing a BFS Class Using the STL |
|
|
743 | (2) |
|
13.4 Applications of Graphs |
|
|
745 | (19) |
|
|
|
746 | (3) |
|
|
|
749 | (4) |
|
|
|
753 | (2) |
|
|
|
755 | (5) |
|
|
|
760 | (3) |
|
|
|
763 | (1) |
|
|
|
764 | (1) |
|
|
|
765 | (1) |
|
|
|
765 | (1) |
|
|
|
766 | (4) |
|
|
|
770 | (1) |
|
CHAPTER 14 External Methods |
|
|
771 | (42) |
|
14.1 A Look at External Storage |
|
|
772 | (3) |
|
14.2 Sorting Data in an External File |
|
|
775 | (8) |
|
|
|
783 | (24) |
|
Indexing an External File |
|
|
785 | (5) |
|
|
|
790 | (3) |
|
|
|
793 | (11) |
|
|
|
804 | (1) |
|
|
|
805 | (2) |
|
|
|
807 | (1) |
|
|
|
807 | (1) |
|
|
|
808 | (1) |
|
|
|
808 | (4) |
|
|
|
812 | (1) |
| APPENDIX A Review of C++ Fundamentals |
|
813 | (76) |
|
|
|
814 | (10) |
|
|
|
814 | (1) |
|
|
|
815 | (1) |
|
|
|
815 | (1) |
|
|
|
816 | (1) |
|
|
|
817 | (1) |
|
|
|
818 | (1) |
|
|
|
818 | (1) |
|
|
|
819 | (1) |
|
Assignments and Expressions |
|
|
820 | (4) |
|
A.2 Input and Output Using iostream |
|
|
824 | (4) |
|
|
|
824 | (2) |
|
|
|
826 | (1) |
|
|
|
827 | (1) |
|
|
|
828 | (4) |
|
|
|
831 | (1) |
|
|
|
832 | (2) |
|
|
|
832 | (1) |
|
|
|
833 | (1) |
|
|
|
834 | (4) |
|
|
|
835 | (1) |
|
|
|
836 | (2) |
|
|
|
838 | (1) |
|
|
|
838 | (6) |
|
|
|
839 | (2) |
|
|
|
841 | (2) |
|
|
|
843 | (1) |
|
|
|
844 | (6) |
|
|
|
845 | (2) |
|
|
|
847 | (3) |
|
|
|
850 | (3) |
|
Structures Within Structures |
|
|
852 | (1) |
|
|
|
852 | (1) |
|
|
|
853 | (7) |
|
|
|
853 | (5) |
|
|
|
858 | (2) |
|
A.10 File Input and Output |
|
|
860 | (14) |
|
|
|
862 | (11) |
|
|
|
873 | (1) |
|
|
|
874 | (2) |
|
Avoiding Duplicate Header Files |
|
|
876 | (1) |
|
A.12 A Comparison to Java |
|
|
876 | (3) |
|
|
|
879 | (4) |
|
|
|
883 | (1) |
|
|
|
884 | (2) |
|
|
|
886 | (2) |
|
|
|
888 | (1) |
| APPENDIX B ASCII Character Codes |
|
889 | (1) |
| APPENDIX C C++ Header Files and Standard Functions |
|
890 | (7) |
| APPENDIX D Mathematical Induction |
|
897 | (6) |
| APPENDIX E Standard Template Library |
|
903 | (12) |
| Glossary |
|
915 | (19) |
| Answers to Self-Test Exercises |
|
934 | (20) |
| Index |
|
954 | |