Explore partition algorithms, which rearrange a container so the elements that meet a criteria are at the beginning of the sequence.
- [Instructor] The partition functions…rearrange a container,…so the elements that meet a criteria are at the beginning.…Let's take a look at an example.…Here I have a working copy of partition.cpp…from chapter six of the exercise files.…I have a predicate function called is even tens,…which checks to see if the tens place…of a number is even,…and we're going to use that for our predicate function here.…Here we have the partition function,…which simply takes the range of the vector…to be modified…and checks it against the predicate function.…
And what happens here,…you notice our prime numbers now…are only greater than 10 and less than 100.…And when I build and run this,…you'll see that all the even numbered tens place…are moved to the front and the odd numbered ones…are left at the end.…Now you'll notice that within each partition,…the elements are no longer in order.…There's a stable partition version of this,…and I'll build and run that.…That leaves the elements in order within their partitions.…
It just takes a little more time and memory…
- 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.