Use generic adjacent_find algorithm with a predicate to find the first name that is lexicographically greater than the next one : adjacent_find « STL Algorithms Non modifying sequence operations « C++






Use generic adjacent_find algorithm with a predicate to find the first name that is lexicographically greater than the next one

 
 
#include <iostream>
#include <string>
#include <algorithm>
#include <cassert>
#include <functional>
#include <deque>
using namespace std;

int main()
{
  deque<string> player(5);
  deque<string>::iterator i;

  player[0] = "PPPP";
  player[1] = "AAAAAA";
  player[2] = "AAAAAA";
  player[3] = "NNNNNNNN";
  player[4] = "RRRRRRRRR";

  
  i = adjacent_find(player.begin(), player.end(), greater<string>());

  cout << *i << endl;

  return 0;
}

/* 
PPPP

 */        
  








Related examples in the same category

1.adjacent_find: search first two elements with equal value
2.Illustrating the generic adjacent_find algorithm
3.adjacent_find: search first two elements for which the second has double the value of the first