Professional Documents
Culture Documents
Lab Report: 7
#include <iostream>
#include <vector>
class Stack {
private:
std::vector<int> elements;
public:
void push(int value) {
elements.push_back(value);
}
int pop() {
if (isEmpty()) {
std::cerr << "Error: Stack is empty." << std::endl;
return -1;
}
bool isEmpty() {
return elements.empty();
}
};
int main() {
Stack myStack;
myStack.push(1);
myStack.push(2);
myStack.push(3);
while (!myStack.isEmpty()) {
int top = myStack.pop();
std::cout << "Popped: " << top << std::endl;
}
return 0;
}
Output:
Popped: 3
Popped: 2
Popped: 1