From the course: Complete Guide to C++ Programming Foundations

Unlock this course with a free trial

Join today to access over 24,800 courses taught by industry experts.

Advanced concepts: Algorithms

Advanced concepts: Algorithms

- [Instructor] Now let's look at some of the most popular algorithms in the C++ STL. These algorithms operate on a wide range of containers and simplify many common operations. They are all defined in the algorithm header I have included in line seven. In the main function, we have a vector of strings that is acting as a very basic inventory with the items you see in line 12. The rest of the code is an exercise in the form of fill in the blanks, as you can see in the comments in lines 15, 22, and 28. In short, the program will first sort the vector alphabetically and print it on the terminal. Then, it will look for the first occurrence of shield and report on the terminal, whether or not it found it. And lastly, it will count the number of potion items in the vector and report it on the terminal. So I will type the appropriate function calls in the spaces marked by comments. To start, let's go to line 15 and use the STD sort function, which sorts elements in a range in ascending…

Contents