template<typename T>
class Stack {
vector<T> data;
public:
void push(T val) { data.push_back(val); }
void pop() { data.pop_back(); }
T top() const { return data.back(); }
bool empty() const { return data.empty(); }
int size() const { return data.size(); }
};
Stack<int> si;
si.push(1); si.push(2); si.push(3);
cout << si.top(); // 3 (LIFO)
si.pop();
cout << si.top(); // 2
Stack<string> ss;
ss.push("hello"); ss.push("world");
cout << ss.top(); // world
Implement a Pair<T, U> class holding two values of possibly different types, with:
Pair(T f, U s)T getFirst() and U getSecond()Click "Run" to execute your code.