1: //is_sorted_until1a.cpp
3: #include <iostream>
4: #include <iomanip>
5: #include <vector>
6: #include <algorithm>
7: using namespace std;
9: int main()
10: {
11: cout << "\nThis program illustrates the use of the STL "
12: "is_sorted_until() algorithm from\n<algorithm> to "
13: "find the first integer that destroys the sorting "
14: "order of a\nvector of integers into the (default) "
15: "ascending order.";
16: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
18: int a[] = {1, 2, 3, 4, 5};
19: int b[] = {1, 2, 3, 6, 5};
20: vector<int> va(a, a+5);
21: vector<int> vb(b, b+5);
22: cout << boolalpha;
23: auto firstUnsortedElementIter = is_sorted_until(va.begin(), va.end());
24: if (firstUnsortedElementIter == va.end())
25: cout << "For 1 2 3 4 5, the sequence is sorted "
26: "(in ascending order)." << endl;
27: else
28: cout << "For 1 2 3 4 5, the sequence sort was "
29: "destroyed at element " << *firstUnsortedElementIter << ".\n";
31: firstUnsortedElementIter = is_sorted_until(vb.begin(), vb.end());
32: if (firstUnsortedElementIter == vb.end())
33: cout << "For 1 2 3 6 5, the sequence is sorted "
34: "(in ascending order)." << endl;
35: else
36: cout << "For 1 2 3 6 5, the sequence sort was "
37: "destroyed at element " << *firstUnsortedElementIter << ".\n";
38: cout << "Press Enter to continue ... "; cin.ignore(80, '\n');
39: }