// Illustrating the generic search algorithm #include #include #include #include #include using namespace std; int main() { cout << "Illustrating the generic search algorithm." << endl; vector vector1(20); deque deque1(5); // Initialize vector1 with 0, 1, ..., 19: int i; for (i = 0; i < 20; ++i) vector1[i] = i; // Initialize deque1 with 5, 6, 7, 8, 9: for (i = 0; i < 5; ++i) deque1[i] = i + 5; // Search for first occurrence of deque1's contents // as a subsequence of the vector contents: vector::iterator k = search(vector1.begin(), vector1.end(), deque1.begin(), deque1.end()); // Verify that 5, 6, 7, 8, 9 occur in vector1 // starting at the position to which k refers: for (i = 0; i < 5; ++i) assert (*(k + i) == i + 5); cout << " --- Ok." << endl; return 0; }