Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Veranschaulicht, wie die Nichtprädikatversion der Funktion adjacent_find Standardvorlagenbibliothek (STL) in Visual C++ verwendet.
template<class ForwardIterator> inline
ForwardIterator adjacent_find(
ForwardIterator First,
ForwardIterator Last
);
Hinweise
Hinweis |
|---|
Die Klasse/Parameternamen im Prototyp stimmen nicht mit der Version in der Headerdatei ab.Einige wurden geändert, um die Lesbarkeit zu verbessern. |
Der Algorithmus sucht adjacent_find aufeinander folgende Paare der übereinstimmenden Elemente in einer Sequenz.Der adjacent_find Algorithmus gibt einen Iterator zurück, der die erste nachfolgende entsprechende Element im Bereich (First, Last) verweisen oder Last , wenn keine solchen Knoten vorhanden sind.Vergleich mit operator== in dieser Nichtprädikatversion des Algorithmus.
Beispiel
// adfind.cpp
// compile with: /EHsc
// Illustrates how to use the non-predicate version of
// adjacent_find function.
//
// Functions:
// adjacent_find - Locate a matching consecutive sequence in a range.
#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
const int ARRAY_SIZE = 8 ;
int IntArray[ARRAY_SIZE] = { 1, 2, 3, 4, 4, 5, 6, 7 } ;
int *location ; // stores the position for the first pair
// of matching consecutive elements.
int i ;
// print content of IntArray
cout << "IntArray { " ;
for(i = 0; i < ARRAY_SIZE; i++)
cout << IntArray[i] << ", " ;
cout << " }" << endl ;
// Find the first pair of matching consecutive elements
// in the range [first, last + 1)
// This version performs matching using operator==
location = adjacent_find(IntArray, IntArray + ARRAY_SIZE) ;
//print the matching consecutive elements if any were found
if (location != IntArray + ARRAY_SIZE) // matching consecutive
// elements found
cout << "Found adjacent pair of matching elements: ("
<< *location << ", " << *(location + 1) << "), " <<
"at location " << location - IntArray << endl;
else // no matching consecutive elements were found
cout << "No adjacent pair of matching elements were found"
<< endl ;
}
Output
IntArray { 1, 2, 3, 4, 4, 5, 6, 7, }
Found adjacent pair of matching elements: (4, 4), at location 3
Anforderungen
Header: <algorithm>
Hinweis