#include <vector>
#include <iostream>
using namespace std;
template <typename iterator>
iterator adjacent_find(iterator beg, iterator data_end) {
iterator found = data_end;
if (beg != data_end) {
iterator ahead = beg;
++ahead;
for (iterator behind = beg; ahead != data_end; ++ahead, ++behind) {
if (*ahead == *behind) {
found = behind;
break;
}
}
}
return(found);
}
template <typename iterator>
void print_all(iterator data_start, iterator data_end) {
for (iterator scan = data_start; scan != data_end; ++scan)
cout << ' ' << *scan;
cout << endl;
}
int main() {
vector<double> V;
cout << "Please enter several values followed by the letter 's':" << endl;
for (;;) {
double x;
cin >> x;
if (cin.fail()) break;
V.push_back(x);
}
cin.clear();
cin.ignore(256, '\n');
vector<double>::iterator pos;
pos = adjacent_find(V.begin(), V.end());
if (pos == V.end())
cout << "Adjacent equal values not found in this vector." << endl;
else
cout << "Adjacent equal values found! First pair equals " << *pos << endl;
return(0);
}