template <class FwdIterator> bool is_sorted( FwdIterator xFirst, FwdIterator xLast );
#include <algorithm>
template <class FwdIterator, class BinaryPredicate> bool is_sorted( 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 qIter;
// Output the vector
cout << "The vector: ";
for (qIter = qV.begin(); qIter != qV.end(); ++qIter) {
cout << *qIter;
}
// Sort test
bool bIsSorted = is_sorted(qV.begin(), qV.end());
cout << (bIsSorted ? " is " : " is not ") << "sorted." << endl;
// Sort the vector
sort(qV.begin(), qV.end());
// Output the new vector
cout << "The vector: ";
for (qIter = qV.begin(); qIter != qV.end(); ++qIter) {
cout << *qIter;
}
// Sort test
bIsSorted = is_sorted(qV.begin(), qV.end());
cout << (bIsSorted ? " is " : " is not ") << "sorted." << endl;
// Keep the window open
cin.get();
return 0;
}
© 20072025 XoaX.net LLC. All rights reserved.