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. SyntaxParameterfirst: 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 valueThis 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. ComplexityComplexity is logarithmic in the range [first, last). Data racesSome of the object in the range [first, last) are accessed. ExceptionsThis 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 1Let'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 2Let's see another simple example: Output: odd: 1 9 3 7 5 Example 3Let'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 4Let's see another simple example: Output: Negative: -1 -4 -2 -5 -3 Positive: 1 3 5 2 4 Next TopicC++ Algorithm |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India