template <class FwdIterator> FwdIterator is_sorted_until( FwdIterator xFirst, FwdIterator xLast );
#include <algorithm>
template <class FwdIterator, class BinaryPredicate> FwdIterator is_sorted_until( FwdIterator xFirst, FwdIterator xLast, BinaryPredicate xComp );
#include <iostream> #include <vector> #include <algorithm> 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 qEndOfSort; vector<char>::iterator qIter; cout << "Vector: "; for (qIter = qV.begin(); qIter != qV.end(); ++qIter) { cout << *qIter; } cout << endl; // Find the end of the sorted items qEndOfSort = is_sorted_until(qV.begin(), qV.end()); ++qEndOfSort; cout << "Sorted: "; for (qIter = qV.begin(); qIter != qEndOfSort; ++qIter) { cout << *qIter; } cout << endl << "After Sort: "; for (qIter = qEndOfSort; qIter != qV.end(); ++qIter) { cout << *qIter; } cout << endl; // Keep the window open cin.get(); return 0; }
© 20072024 XoaX.net LLC. All rights reserved.