Chapter 11. Generic Algorithms
CONTENTS Section 11.1 Overview392Section 11.2 A First Look at the Algorithms395Section 11.3 Revisiting Iterators405Section 11.4 Structure of Generic Algorithms419Section 11.5 Container-Specific Algorithms421Chapter Summary424Defined Terms424The library containers define a surprisingly small set of operations. Rather than adding lots of functionality to the containers, the library instead provides a set of algorithms, most of which are independent of any particular container type. These algorithms are "generic:" They operate on different types of containers and on elements of various types.The generic algorithms, and a more detailed look at iterators, form the subject matter of this chapter.generic algorithms: "algorithms" because they implement common operations; and "generic" because they operate across multiple container typesnot only library types such as vector or list, but also the built-in array type, and, as we shall see, over other kinds of sequences as well. The algorithms also can be used on container types we might define ourselves, as long as our types conform to the standard library conventions.Most of the algorithms operate by traversing a range of elements bounded by two iterators. Typically, as the algorithm traverses the elements in the range, it operates on each element. The algorithms obtain access to the elements through the iterators that denote the range of elements to traverse.