template <class BidirIter, class Predicate> BidirIter stable_partition( BidirIter xFirst, BidirIter xLast, Predicate xTest );
#include <algorithm>
#include <iostream>
#include <vector>
#include <algorithm>
bool GreaterThanZ(char cTest) {
return (cTest > 'Z');
}
int main()
{
using namespace std;
// Create a vector instance
vector<char> qV;
qV.push_back('X');
qV.push_back('o');
qV.push_back('a');
qV.push_back('X');
qV.push_back('.');
qV.push_back('n');
qV.push_back('e');
qV.push_back('t');
vector<char>::iterator qIter;
// Output the vector
cout << "Original: ";
for (qIter = qV.begin(); qIter != qV.end(); ++qIter) {
cout << *qIter;
}
cout << endl;
// Partition the vector
vector<char>::iterator qPartEnd;
qPartEnd = stable_partition(qV.begin(), qV.end(), GreaterThanZ);
// Output the patitioned vector
cout << "Partitioned: ";
for (qIter = qV.begin(); qIter != qPartEnd; ++qIter) {
cout << *qIter;
}
cout << " | ";
for (qIter = qPartEnd; qIter != qV.end(); ++qIter) {
cout << *qIter;
}
cout << endl;
// Keep the window open
cin.get();
return 0;
}
© 20072025 XoaX.net LLC. All rights reserved.