Back to slide -- Keyboard shortcut: 'u'  previous -- Keyboard shortcut: 'p'  next -- Keyboard shortcut: 'n'          algorithms/for-each-examples-f15/adjacent-1.cpp - Following the advice: Solve the problem with a more appropriate algorithm.Lecture 6 - slide 23 : 40
Program 2

// A more straightforward solution - using the adjent_find algorithm

#include <iostream>
#include <algorithm>
#include <list>

int main(){
  using namespace std;

  list<int> lst{3, 15, 9, 11, 13, 15, 21};

  if(adjacent_find(lst.begin(), lst.end(), greater<int>{}) != lst.end())    // find a pair of elements out of order.
    cout << "The list lst is NOT sorted" << endl;                           // greater is shown in the next program.
  else
    cout << "The list lst is sorted" << endl;
}