Demonstrating Functions sort and binary_search

Figure 7.18 begins by creating an unsorted array of strings (lines 13–14) and displaying the contents of the 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. We’ll discuss the complete details of class template array’s begin and end functions in later chapters. As you’ll see, function sort can be used to sort the elements of several different types of data structures. Lines 24–26 display the contents of the sorted array.

 1   // Fig. 7.18: fig07_18.cpp 2   // Sorting ...

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.