From the course: C++ Templates and the STL
Unlock this course with a free trial
Join today to access over 22,700 courses taught by industry experts.
Partitions - C++ Tutorial
From the course: C++ Templates and the STL
Partitions
- [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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
(Locked)
About STL algorithms1m 42s
-
(Locked)
Testing conditions2m 36s
-
(Locked)
Searching and counting4m 38s
-
(Locked)
Replacing and removing4m 14s
-
(Locked)
Modifying algorithms5m 46s
-
(Locked)
Partitions2m 52s
-
(Locked)
Sorting3m 42s
-
(Locked)
Merging sequences2m 4s
-
(Locked)
Binary searches3m 57s
-
(Locked)
-