#include #include using namespace std; // Recursive function. bool member_of(int x, vector v) { // Base case. if (v.size() == 1) return x == v[0]; // Either x is equal to the head of the vector, or ... if (x == v[0]) return true; // ... x is in the rest of the vector (recursive case). v.erase(v.begin()); return member_of(x, v); } void test(const int value, const vector& vec) { cout << value << " is"; bool found = member_of(value, vec); if (!found) cout << " not"; cout << " in the vector." << endl; } int main() { vector vec; vec.push_back(30); vec.push_back(10); vec.push_back(50); vec.push_back(80); vec.push_back(60); vec.push_back(12); vec.push_back(40); vec.push_back(20); vec.push_back(70); cout << "The vector: "; for (int i : vec) cout << i << " "; cout << endl << endl; test(50, vec); test(65, vec); test(80, vec); test(47, vec); }