Learn how searching and counting algorithms include find, search, and count, along with if and if-not versions of find and count.
- [Instructor] The STL provides a number of algorithms…for searching and counting elements in a sequence.…Here I have a working copy of search.cpp…from chapter six of the exercise files.…Notice here that the vector I'm using is const-qualified.…All of these functions are constant safe…as they don't change the values of anything…in the sequence in the container.…We'll start here with the find function.…The find function does a sequential search,…using the equal to comparison.…
If the compared value is found it returns…an iterator pointing to that value…and if the value is not found,…it returns the end point iterator.…So I can test here for the end point iterator…and if it's not at the end then I know that…I found the element and when I build and run,…it finds the number 41 at index 12.…You notice I'm getting index 12…by subtracting the beginning from the iterator.…The find_if function uses…a unary operator and you'll notice…that I have one up here, is_odd.…
Checks to see if what we're looking at…is odd so I can say is_odd int.…
- Template fundamentals
- STL containers
- Accessing iterators
- Output, forward, and bidirectional iterators
- The transform function
- Transforming strings and types
- Arithmetic, relational, and logical functions
- STL algorithms
Skill Level Intermediate
2. STL Containers
3. STL Iterators
5. STL Functions
6. STL Algorithm
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.