adjacent_find 알고리듬은 시퀀스에서 동일한 원소가 이웃하고 있는 쌍을 찾아, 앞쪽 원소를 가리키는 반복자를 리턴합니다.
다음은 예제 코드입니다.
// Illustrating the generic adjacent_find algorithm
#include <cassert>
#pragma hdrstop
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
int main()
{
string *i, player[5] = {"Pele", "Platini", "Maradona", "Maradona", "Rossi"};
// Find the first pair of equal consecutive names:
i = adjacent_find(player, player + 5);
assert (*i == "Maradona" && *(i+1) == "Maradona");
// Find the first name that is lexicographically
// greater than the following name:
i = adjacent_find(player, player + 5, greater<string>());
assert (*i == "Platini" && *(i+1) == "Maradona");
return 0;
}
|