... array (lines 17–19). Next, line 21 uses C++ Standard Library function sort to sort the elements of the array colors into ascending order. The sort function’s arguments specify the range of elements that should be sorted—in this case, the entire array. The arguments colors.begin() and colors.end() represent the array’s beginning and end, respectively—we’ll discuss the complete details of begin and end in Chapter 15. As you’ll see, function sort can be used to sort the elements of several different types of data structures. Lines 25–27 display the contents of the sorted array.

Fig. 7.15 Sorting and searching arrays.

Alternate View

 1   // Fig. 7.15: ...

Get C++ How to Program, 10/e now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.