Javatpoint Logo
Javatpoint Logo

C++ Algorithm partition_point()

C++ Algorithm partition_point() function is used to return the first element in the given range for which pred is not true. The elements are sorted in a way that the elements which satisfy the condition come before those who do not satisfy.

Syntax

Parameter

first: An forward iterator pointing to the first element in the range to check for a condition.

last: A forward iterator pointing to the past last element of the range.

pred: A user defined unary predicate function that defines the condition to be tested.

Return value

This function returns a forward iterator to point to the first element that does not fulfill the condition tested by pred or returns last if one is not found.

Complexity

Complexity is logarithmic in the range [first, last).

Data races

Some of the object in the range [first, last) are accessed.

Exceptions

This function throws an exception if either an element's comparison or an operation on iterator throws an exception.

Note: The invalid parameters cause an undefined behavior.

Example 1

Let's see the simple example to demonstrate the use of partition_point():

Output:

Before partition:
    8 2 6 4 
After partition:
    5 3 7 1 9

Example 2

Let's see another simple example:

Output:

odd: 1 9 3 7 5

Example 3

Let's see another simple example:

Output:

The partitioned vector is : 2 6 8 1 5 7 
The vector elements returning true for condition are : 2 6 8 

Example 4

Let's see another simple example:

Output:

Negative:  -1 -4 -2 -5 -3
Positive:  1 3 5 2 4

Next TopicC++ Algorithm




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA