Or login with:
#include <algorithm> template < class BidirectionalIterator, class Predicate > BidirectionalIterator partition( BidirectionalIterator first, BidirectionalIterator last, Predicate comp );Parameters:
| Parameter | Description |
|---|---|
| first | A bidirectional iterator addressing the position of the first element in the range to be partitioned |
| last | A bidirectional iterator addressing the position one past the final element in the range to be partitioned |
| comp | User-defined predicate function object that defines the condition to be satisfied if an element is to be classified. A predicate takes a single argument and returns true or false |
last - first applications of pred and at most (last - first)/2 swaps.#include <iostream> #include <vector> #include <algorithm> using namespace std; /* Determines if an integer is divisible by 3. n contains an integer Returns true if n is divisible by 3, and otherwise false. */ bool isDivisibleByThree ( int n //in ) { return (n%3 == 0); } int main() { int a[] ={11, 7, 9, 4, 8, 12, 2, 5, 3, 10, 1, 6}; vector<int> v(a, a+12); cout <<"\nHere are the contents of the vector:\n"; for (vector<int>::size_type i=0; i<v.size(); i++) cout <<v.at(i)<<" "; vector<int>::iterator p = partition(v.begin(), v.end(), isDivisibleByThree); cout <<"\nAnd here are the contents of the partitioned vector:\n"; for (vector<int>::size_type i=0; i<v.size(); i++) cout <<v.at(i)<<" "; cout <<"\nThe iterator p returned by the algorithm points to "; if (p == v.end()) cout <<"\nthe end of the ouput container."; else cout <<"the value "<<*p<<"."; return 0; }
You must login to leave a messge