is_partitioned(): This function is available in the file stl_algo.h. This function is used to checks whether the sequence is partitioned.
Parameters: Three parameters are required for this function.
__first – An input iterator.
__last – An input iterator.
__pred – A predicate.
This function returns true if the range [__first,__last) is partitioned by __pred, i.e. if all elements that satisfy __pred appear before those that do not.
Syntax:
is_partitioned(__first, __last, __pred)
For Example:
arr = {1,2,3,4}
is_partitioned(arr.begin(),arr.end(),[](int i){return i%2==0;}) = > It return false (0).
Approach
C++
#include <bits/stdc++.h>using namespace std;int main(){vector<int> arr = {1, 2, 3, 4};cout << is_partitioned(arr.begin(), arr.end(), [](int i){ return i % 2 == 0; })<< "\n";return 0;}
No comments:
Post a Comment