面试题答案
一键面试#include <iostream>
#include <vector>
class Stack {
private:
std::vector<int> data;
public:
void push(int value) {
data.push_back(value);
}
void pop() {
if (!data.empty()) {
data.pop_back();
}
}
int top() {
if (!data.empty()) {
return data.back();
}
throw std::runtime_error("Stack is empty");
}
bool isEmpty() {
return data.empty();
}
};