Data Structures and Algorithms with Object-Oriented Design Patterns in C++Preface This book was motivated by my experience in teaching the course E&CE 250: Algorithms and Data Structures
Trang 1Data Structures and Algorithms with Object-Oriented Design Patterns in C++
Data Structures and Algorithms
with Object-Oriented Design Patterns in
C++
Bruno R Preiss B.A.Sc., M.A.Sc., Ph.D., P.Eng.
Associate Professor Department of Electrical and Computer Engineering University of Waterloo, Waterloo, Canada
Trang 2Graphs and Graph Algorithms
Copyright © 1997 by Bruno R Preiss, P.Eng All rights reserved
Data Structures and Algorithms with Object-Oriented Design Patterns in C++
http://www.pads.uwaterloo.ca/Bruno.Preiss/books/opus4/html/book.html (2 of 2) [20/10/2001 01:19:31]
Trang 3Data Structures and Algorithms with Object-Oriented Design Patterns in C++
Colophon
Copyright © 1997 by Bruno R Preiss
All rights reserved No part of this publication may be reproduced, stored in a retrieval system, or
transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise,without the prior written permission of the author
This book was prepared with LaTeX and reproduced from camera-ready copy supplied by the author.The book is typeset using the Computer Modern fonts designed by Donald E Knuth with various
additional glyphs designed by the author and implemented using METAFONT
METAFONT is a trademark of Addison Wesley Publishing Company
SPARCstation, Solaris, and Java are registered trademarks of Sun Microsystems
TeX is a trademark of the American Mathematical Society
UNIX is a registered trademark of AT&T Bell Laboratories
Copyright © 1997 by Bruno R Preiss, P.Eng All rights reserved
Colophon
Trang 4Data Structures and Algorithms with Object-Oriented Design Patterns in C++
Dedication
To my children, Anna Kristina, Katherine Lila
and Alexander Edgar
Copyright © 1997 by Bruno R Preiss, P.Eng All rights reserved
Dedication
http://www.pads.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page2.html [20/10/2001 01:19:33]
Trang 5Data Structures and Algorithms with Object-Oriented Design Patterns in C++
Preface
This book was motivated by my experience in teaching the course E&CE 250: Algorithms and Data Structures in the Computer Engineering program at the University of Waterloo I have observed that the advent of object-oriented methods and the emergence of object-oriented design patterns has lead to a
profound change in the pedagogy of data structures and algorithms The successful application of thesetechniques gives rise to a kind of cognitive unification: Ideas that are disparate and apparently unrelatedseem to come together when the appropriate design patterns and abstractions are used
This paradigm shift is both evolutionary and revolutionary On the one hand, the knowledge base growsincrementally as programmers and researchers invent new algorithms and data structures On the otherhand, the proper use of object-oriented techniques requires a fundamental change in the way the
programs are designed and implemented Programmers who are well schooled in the procedural waysoften find the leap to objects to be a difficult one
Trang 6Data Structures and Algorithms with Object-Oriented Design Patterns in C++
Goals
The primary goal of this book is to promote object-oriented design using C++ and to illustrate the use of
the emerging object-oriented design patterns Experienced object-oriented programmers find that certain
ways of doing things work best and that these ways occur over and over again The book shows howthese patterns are used to create good software designs In particular, the following design patterns are
used throughout the text: singleton, container, iterator, adapter and visitor.
Virtually all of the data structures are presented in the context of a single, unified, polymorphic class hierarchy This framework clearly shows the relationships between data structures and it illustrates how polymorphism and inheritance can be used effectively In addition, algorithmic abstraction is used
extensively when presenting classes of algorithms By using algorithmic abstraction, it is possible todescribe a generic algorithm without having to worry about the details of a particular concrete realization
of that algorithm
A secondary goal of the book is to present mathematical tools just in time Analysis techniques and
proofs are presented as needed and in the proper context In the past when the topics in this book weretaught at the graduate level, an author could rely on students having the needed background in
mathematics However, because the book is targeted for second- and third-year students, it is necessary
to fill in the background as needed To the extent possible without compromising correctness, the
presentation fosters intuitive understanding of the concepts rather than mathematical rigor
Copyright © 1997 by Bruno R Preiss, P.Eng All rights reserved
Goals
http://www.pads.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page4.html [20/10/2001 01:19:34]
Trang 7Data Structures and Algorithms with Object-Oriented Design Patterns in C++
Approach
One cannot learn to program just by reading a book It is a skill that must be developed by practice.Nevertheless, the best practitioners study the works of others and incorporate their observations into theirown practice I firmly believe that after learning the rudiments of program writing, students should beexposed to examples of complex, yet well-designed program artifacts so that they can learn about thedesigning good software
Consequently, this book presents the various data structures and algorithms as complete C++ programfragments All the program fragments presented in this book have been extracted automatically from thesource code files of working and tested programs
The full functionality of the proposed draft ANSI standard C++ language is used in the
examples including templates, exceptions and run-time type information[3] It has been my experiencethat by developing the proper abstractions, it is possible to present the concepts as fully functional
programs without resorting to pseudo-code or to hand-waving.
Copyright © 1997 by Bruno R Preiss, P.Eng All rights reserved
Approach
Trang 8Data Structures and Algorithms with Object-Oriented Design Patterns in C++
Outline
This book presents material identified in the Computing Curricula 1991 report of the ACM/IEEE-CS
Joint Curriculum Task Force[38] The book specifically addresses the following knowledge units: AL1:
Basic Data structures, AL2: Abstract Data Types, AL3: Recursive Algorithms, AL4: Complexity
Analysis, AL6: Sorting and Searching, and AL8: Problem-Solving Strategies The breadth and depth ofcoverage is typical of what should appear in the second or third year of an undergraduate program incomputer science/computer engineering
In order to analyze a program, it is necessary to develop a model of the computer Chapter developsseveral models and illustrates with examples how these models predict performance Both average-caseand worst-case analyses of running time are considered Recursive algorithms are discussed and it isshown how to solve a recurrence using repeated substitution This chapter also reviews arithmetic andgeometric series summations, Horner's rule and the properties of harmonic numbers
Chapter introduces asymptotic (big-oh) notation and shows by comparing with Chapter that theresults of asymptotic analysis are consistent with models of higher fidelity In addition to , thischapter also covers other asymptotic notations ( , and ) and develops the asymptotic
properties of polynomials and logarithms
Chapter introduces the foundational data structures the array and the linked list Virtually all the
data structures in the rest of the book can be implemented using either one of these foundational
structures This chapter also covers multi-dimensional arrays and matrices
Chapter deals with abstraction and data types It presents the recurring design patterns used
throughout the text as well a unifying framework for the data structures presented in the subsequent
chapters In particular, all of the data structures are viewed as abstract containers.
Chapter discusses stacks, queues and deques This chapter presents implementations based on bothfoundational data structures (arrays and linked lists) Applications for stacks and queues and queues arepresented
Chapter covers ordered lists, but sorted and unsorted In this chapter, a list is viewed as a searchable container Again several applications of lists are presented.
Chapter introduces hashing and the notion of a hash table This chapter addresses the design ofhashing functions for the various basic data types as well as for the abstract data types described inChapter Both scatter tables and hash tables are covered in depth and analytical performance results
Outline
http://www.pads.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page6.html (1 of 3) [20/10/2001 01:19:36]
Trang 9are derived.
Chapter introduces trees and describes their many forms Both depth-first and breadth-first tree
traversals are presented Completely generic traversal algorithms based on the use of the visitor design pattern are presented, thereby illustrating the power of algorithmic abstraction This chapter also shows
how trees are used to represent mathematical expressions and illustrates the relationships between
traversals and the various expression notations (prefix, infix and postfix)
Chapter addresses trees as searchable containers Again, the power of algorithmic abstraction is
demonstrated by showing the relationships between simple algorithms and balancing algorithms Thischapter also presents average case performance analyses and illustrates the solution of recurrences bytelescoping
Chapter presents several priority queue implementations, including binary heaps, leftist heaps andbinomial queues In particular this chapter illustrates how a more complicated data structure (leftist heap)extends an existing one (tree) Discrete-event simulation is presented as an application of priority queues
Chapter covers sets and multisets Also covered are partitions and disjoint set algorithms The lattertopic illustrates again the use of algorithmic abstraction
Techniques for dynamic storage management are presented in Chapter This is a topic that is notfound often in texts of this sort However, the features of C++ which allow the user to redefine the new
and delete operators make this topic approachable
Chapter surveys a number of algorithm design techniques Included are brute-force and greedy
algorithms, backtracking algorithms (including branch-and-bound), divide-and-conquer algorithms and
dynamic programming An object-oriented approach based on the notion of an abstract solution space and an abstract solver unifies much of the discussion This chapter also covers briefly random number
generators, Monte Carlo methods, and simulated annealing
Chapter covers the major sorting algorithms in an object-oriented style based on the notion of an
abstract sorter Using the abstract sorter illustrates the relationships between the various classes of
sorting algorithm and demonstrates the use of algorithmic abstractions
Finally, Chapter presents an overview of graphs and graph algorithms Both depth-first and
breadth-first graph traversals are presented Topological sort is viewed as yet another special kind of
traversal Generic traversal algorithms based on the visitor design pattern are presented, once more
illustrating algorithmic abstraction This chapter also covers various shortest path algorithms and
minimum-spanning-tree algorithms
At the end of each chapter is a set of exercises and a set of programming projects The exercises aredesigned to consolidate the concepts presented in the text The programming projects generally requirethe student to extend the implementation given in the text
Outline
Trang 10Copyright © 1997 by Bruno R Preiss, P.Eng All rights reserved.
Outline
http://www.pads.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page6.html (3 of 3) [20/10/2001 01:19:36]
Trang 11Data Structures and Algorithms with Object-Oriented Design Patterns in C++
Suggested Course Outline
This text may be used in either a one semester or a two semester course The course which I teach atWaterloo is a one-semester course that comprises 36 lecture hours on the following topics:
Review of the fundamentals of programming in C++ and an overview of object-oriented
programming with C++ (Appendix ) [4 lecture hours]
Depending on the background of students, a course instructor may find it necessary to review features of
the C++ language For example, an understanding of templates is required for the foundational data
Copyright © 1997 by Bruno R Preiss, P.Eng All rights reserved
Suggested Course Outline
Trang 12Data Structures and Algorithms with Object-Oriented Design Patterns in C++
Online Course Materials
Additional material supporting this book can be found on the world-wide web at the URL:
http://www.pads.uwaterloo.ca/Bruno.Preiss/books/opus4
In particular, you will find there the source code for all the program fragments in this book as well as anerrata list
Waterloo, Canada
Copyright © 1997 by Bruno R Preiss, P.Eng All rights reserved
Online Course Materials
http://www.pads.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page8.html [20/10/2001 01:19:38]
Trang 13Data Structures and Algorithms with Object-Oriented Design Patterns in C++
■ Visitors
■ Adapters
■ Singletons
■ Pointers
■ Classes and Objects
■ Inheritance
■ Other Features
■
❍
How This Book Is Organized
Models and Asymptotic Analysis
■
❍
●
Contents
Trang 14Foundational Data Structures
■ Abstract Data Types and the Class Hierarchy
■ Data Structures
■ Algorithms
■ Algorithm Analysis
A Detailed Model of the Computer
The Basic Axioms
■
A Simple Example-Arithmetic Series Summation
■ Array Subscripting Operations
■ Another Example-Horner's Rule
■ Analyzing Recursive Functions
Solving Recurrence Relations-Repeated Substitution
■
■
Yet Another Example-Finding the Largest Element of an Array
■ Average Running Times
■ About Harmonic Numbers
■ Best-Case and Worst-Case Running Times
■ The Last Axiom
■
❍
A Simplified Model of the Computer
An Example-Geometric Series Summation
■ About Arithmetic Series Summation
■ Example-Geometric Series Summation Again
■ About Geometric Series Summation
■ Example-Computing Powers
■ Example-Geometric Series Summation Yet Again
■ Properties of Big Oh
■ About Polynomials
■ About Logarithms
Trang 15Tight Big Oh Bounds
■ More Big Oh Fallacies and Pitfalls
■ Conventions for Writing Big Oh Expressions
■
An Asymptotic Lower Bound-Omega
A Simple Example
■ About Polynomials Again
■
❍
More Notation-Theta and Little Oh
❍
Asymptotic Analysis of Algorithms
Rules For Big Oh Analysis of Running Time
■ Example-Prefix Sums
■ Example-Fibonacci Numbers
■ Example-Bucket Sort
■ Reality Check
■ Checking Your Analysis
■ Copy Constructor
■ Destructor
■ Array Member Functions
■ Array Subscripting Operator
■ Resizing an Array
■ Default Constructor
■ Destructor and Purge Member Function
■ Accessors
Trang 16■ Copy Constructor and Assignment Operator
Array Subscript Calculations
■ Two-Dimensional Array Implementation
■ Multi-Dimensional Subscripting in C++
■ Canonical Matrix Multiplication
Data Types and Abstraction
Abstract Data Types
❍
Design Patterns
Class Hierarchy
■ Objects
■ Ownership of Contained Objects
■ Associations
Trang 18Tail, EnqueueHead, and DequeueTail Member Functions
■ Doubly-Linked and Circular Lists
■ Exercises
■ Finding Items in a List
■ Removing Items from a List
■ Positions of Items in a List
■ Finding the Position of an Item and Accessing by Position
■ Inserting an Item at an Arbitrary Position
■ Removing Arbitrary Items by Position
■ Finding Items in a List
■ Removing Items from a List
■ Positions of Items in a List
■ Finding the Position of an Item and Accessing by Position
■ Inserting an Item at an Arbitrary Position
■ Removing Arbitrary Items by Position
■
■
Performance Comparison: ListAsArray vs ListAsLinkedList
■ Applications
■ Finding Items in a Sorted List
■ Removing Items from a List
Trang 19Inserting Items in a Sorted List
■ Other Operations on Sorted Lists
■ Performance Comparison: SortedListAsArray vs SortedListAsList
■ Applications
Implementation
■ Analysis
Hashing, Hash Tables and Scatter Tables
Hashing-The Basic Idea
Example
■ Keys and Hash Functions
Avoiding Collisions
■ Spreading Keys Evenly
■ Ease of Computation
■ Multiplication Method
■ Fibonacci Hashing
■ Character String Keys
■ Hashing Objects
■ Hashing Containers
■ Using Associations
■ Inserting and Removing Items
■ Finding an Item
Trang 20Average Case Analysis
■ Scatter Tables
Chained Scatter Table
Implementation
■ Constructors and Destructor
■ Inserting and Finding an Item
■ Removing Items
■ Worst-Case Running Time
■ Double Hashing
■ Implementation
Constructors and Destructor
■ Inserting Items
■ Finding Items
■ Removing Items
■ Alternate Representations for Trees
■ Inorder Traversal
Trang 21Breadth-First Traversal
■ Expression Trees
Infix Notation
■ Prefix Notation
■ Postfix Notation
■ Breadth-First Traversal
■ Operator Member Functions
■ Constructor, Destructor, and Purge Member Function
■ Constructors
■ Destructor and Purge Member Functions
Trang 22Comparing Trees
■ Applications
■
❍
Searching a Search Tree
Searching an M-way Tree
■ Searching a Binary Tree
■ Unsuccessful Search
■ Traversing a Search Tree
■
❍
Implementing Search Trees
Binary Search Trees
Inserting Items in a Binary Search Tree
■
■
Removing Items from a Binary Search Tree
■
■
❍
AVL Search Trees
Implementing AVL Trees
Inserting Items into an AVL Tree
Balancing AVL Trees
■ Single Rotations
Trang 23Double Rotations
■ Implementation
■ Removing Items from an AVL Tree
■
M-Way Search Trees
Implementing M-Way Search Trees
Implementation
■ Member Functions
■ Inorder Traversal
■ Private Member Functions
Trang 24Putting Items into a Binary Heap
■ Removing Items from a Binary Heap
■ Leftist Heaps
Leftist Trees
■ Implementation
■ Removing Items from a Leftist Heap
■ Implementation
Heap-Ordered Binomial Trees
■ Binomial Queues
■ Member Variables
■ Removing an Item from a Binomial Queue
Trang 25Comparing Sets
■ Bit-Vector Sets
Basic Operations
■ Union, Intersection and Difference
Implementation
■ Constructors and Destructor
■ Union by Height or Rank
■ Releasing an Area
Trang 26Doubly Linked Free Storage
Implementation
Constructor and Destructor
■ Releasing an Area
■ Acquiring an Area
■ Releasing an Area
Algorithmic Patterns and Problem Solvers
Brute-Force and Greedy Algorithms
Example-Counting Change
Brute-Force Algorithm
■ Greedy Algorithm
■ Abstract Backtracking Solvers
Depth-First Solver
■ Breadth-First Solver
■ Example-Merge Sorting
Trang 27Running Time of Divide-and-Conquer Algorithms
Case 1 ( )
■
Case 2 ( )
■ Case 3 ( )
■ Summary
■
■
Example-Matrix Multiplication
■ Bottom-Up Algorithms: Dynamic
Programming
Example-Generalized Fibonacci Numbers
■ Example-Computing Binomial Coefficients
■ Application: Typesetting Problem
Example
■ Implementation
■
■
❍
Randomized Algorithms
Generating Random Numbers
The Minimal Standard Random Number Generator
■ Implementation
Sorting and Sorters
Sorter Class Hierarchy
Trang 28Average Running Time
■ Binary Insertion Sort
■ Exchange Sorting
Bubble Sort
■ Quicksort
Implementation
■
■
Running Time Analysis
Worst-Case Running Time
■ Best-Case Running Time
■
■
Average Running Time
■ Selecting the Pivot
Building the Heap
Running Time Analysis
■ The Sorting Phase
■ Two-Way Merge Sorting
■ Running Time Analysis
Trang 29Graphs and Graph Algorithms
Basics
Directed Graphs
■ Terminology
■ More Terminology
■ Directed Acyclic Graphs
■ Undirected Graphs
■ Terminology
■ Labeled Graphs
■ Representing Graphs
Adjacency Matrices
■ Sparse vs Dense Graphs
■ Adjacency Lists
■ Abstract Graphs and Digraphs
Accessors and Mutators
■ Iterators
■ Graph Traversals
■
■
Implementing Undirected Graphs
Using Adjacency Matrices
■ Using Adjacency Lists
■
■
Edge-Weighted and Vertex-Weighted Graphs
■ Comparison of Graph Representations
Space Comparison
■ Time Comparison
Trang 30Running Time Analysis
■ Topological Sort
Implementation
■ Running Time Analysis
■
■
Graph Traversal Applications:
Testing for Cycles and Connectedness
Connectedness of an Undirected Graph
■ Connectedness of a Directed Graph
■ Testing for Cycles in a Directed Graph
■ Implementation
■ Running Time Analysis
■ Running Time Analysis
■
■
❍
Minimum-Cost Spanning Trees
Constructing Spanning Trees
■ Minimum-Cost Spanning Trees
■ Prim's Algorithm
C++ and Object-Oriented Programming
Variables, Pointers and References
❍
●
Contents
http://www.pads.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page9.html (18 of 20) [20/10/2001 01:19:41]
Trang 31Pointers Are Variables
Pass By Value
■ Pass By Reference
The Trade-off
■ Constant Parameters
■
■
❍
Objects and Classes
Member Variables and Member Functions
■ Constructors and Destructors
Default Constructor
■ Copy Constructor
■ The Copy Constructor, Parameter Passing and Function Return Values
■ Destructors
■
■
❍
Inheritance and Polymorphism
Derivation and Inheritance
Derivation and Access Control
■ Algorithmic Abstraction
■
■
Multiple Inheritance
■ Run-Time Type Information and Casts
Trang 32Copyright © 1997 by Bruno R Preiss, P.Eng All rights reserved.
Contents
http://www.pads.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page9.html (20 of 20) [20/10/2001 01:19:41]
Trang 33Data Structures and Algorithms with Object-Oriented Design Patterns in C++
Trang 34Data Structures and Algorithms with Object-Oriented Design Patterns in C++
What This Book Is About
This book is about the fundamentals of data structures and algorithms the basic elements from which
large and complex software artifacts are built To develop a solid understanding of a data structurerequires three things: First, you must learn how the information is arranged in the memory of the
computer Second, you must become familiar with the algorithms for manipulating the informationcontained in the data structure And third, you must understand the performance characteristics of thedata structure so that when called upon to select a suitable data structure for a particular application, youare able to make an appropriate decision
This book also illustrates object-oriented design and it promotes the use of common, object-orienteddesign patterns The algorithms and data structures in the book are presented in the C++ programminglanguage Virtually all the data structures are presented in the context of a single class hierarchy Thiscommitment to a single design allows the programs presented in the later chapters to build upon theprograms presented in the earlier chapters
Copyright © 1997 by Bruno R Preiss, P.Eng All rights reserved
What This Book Is About
http://www.pads.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page11.html [20/10/2001 01:19:42]
Trang 35Data Structures and Algorithms with Object-Oriented Design Patterns in C++
Object-Oriented Design
Traditional approaches to the design of software have been either data oriented or process oriented.
Data-oriented methodologies emphasize the representation of information and the relationships betweenthe parts of the whole The actions which operate on the data are of less significance On the other hand,process-oriented design methodologies emphasize the actions performed by a software artifact; the dataare of lesser importance
It is now commonly held that object-oriented methodologies are more effective for managing the
complexity which arises in the design of large and complex software artifacts than either data-oriented or
process-oriented methodologies This is because data and processes are given equal importance Objects
are used to combine data with the procedures that operate on that data The main advantage of using
objects is that they provide both abstraction and encapsulation.
Trang 36Data Structures and Algorithms with Object-Oriented Design Patterns in C++
Abstraction
Abstraction can be thought of as a mechanism for suppressing irrelevant details while at the same timeemphasizing relevant ones An important benefit of abstraction is that it makes it easier for the
programmer to think about the problem to be solved
For example, procedural abstraction lets the software designer think about the actions to be performed without worrying about how those actions are implemented Similarly, data abstraction lets the software
designer think about the objects in a program and the interactions between those objects without having
to worry about how those objects are implemented
There are also many different levels of abstraction The lower the levels of abstraction expose more of
the details of an implementation whereas the higher levels hide more of the details
Copyright © 1997 by Bruno R Preiss, P.Eng All rights reserved
Abstraction
http://www.pads.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page13.html [20/10/2001 01:19:43]
Trang 37Data Structures and Algorithms with Object-Oriented Design Patterns in C++
Encapsulation
Encapsulation aids the software designer by enforcing information hiding Objects encapsulate data and the procedures for manipulating that data In a sense, the object hides the details of the implementation
from the user of that object
There are two very real benefits from encapsulation conceptual and physical independence Conceptual
independence results from hiding the implementation of an object from the user of that object
Consequently, the user is prevented from doing anything with an object that depends on the
implementation of that object This is desirable because it allows the implementation to be changedwithout requiring the modification of the user's code
Physical independence arises from the fact that the behavior of an object is determined by the objectitself The behavior of an object is not determined by some external entity As a result, when we perform
an operation on an object, there are no unwanted side-effects
Copyright © 1997 by Bruno R Preiss, P.Eng All rights reserved
Encapsulation
Trang 38Data Structures and Algorithms with Object-Oriented Design Patterns in C++
Object Hierarchies and Design
Patterns
There is more to object-oriented programming than simply encapsulating in an object some data and the
procedures for manipulating those data Object-oriented methods deal also with the classification of objects and they address the relationships between different classes of objects.
The primary facility for expressing relationships between classes of objects is derivation new classes can be derived from existing classes What makes derivation so useful is the notion of inheritance.
Derived classes inherit the characteristics of the classes from which they are derived In addition,
inherited functionality can be overridden and additional functionality can be defined in a derived class
A feature of this book is that virtually all the data structures are presented in the context of a single classhierarchy In effect, the class hierarchy is a taxonomy of data structures Different implementations of agiven abstract data structure are all derived from the same abstract base class Related base classes are inturn derived from classes that abstract and encapsulate the common features of those classes
In addition to dealing with hierarchically related classes, experienced object-oriented designers alsoconsider very carefully the interactions between unrelated classes With experience, a good designerdiscovers the recurring patterns of interactions between objects By learning to use these patterns, yourobject-oriented designs will become more flexible and reusable
Recently, programmers have to started name the common design patterns In addition, catalogs of thecommon patterns are now being compiled and published[14]
The following object-oriented design patterns are used throughout this text:
Copyright © 1997 by Bruno R Preiss, P.Eng All rights reserved
Object Hierarchies and Design Patterns
http://www.pads.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page15.html (1 of 2) [20/10/2001 01:19:44]
Trang 39Object Hierarchies and Design Patterns
Trang 40Data Structures and Algorithms with Object-Oriented Design Patterns in C++
Containers
A container is an object that holds within it other objects A container has a capacity, it can be full or
empty, and objects can be inserted and withdrawn from a container In addition, a searchable container
is a container that supports efficient search operations
Copyright © 1997 by Bruno R Preiss, P.Eng All rights reserved
Containers
http://www.pads.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page16.html [20/10/2001 01:19:44]