#include
#include
class BaseContainer {
public:
virtual void printSize() const = 0;
virtual void addElement(int element) = 0;
};
class Array : public BaseContainer {
private:
std::vector elements;
public:
void printSize() const override {
std::cout << "Array size: " << elements.size() << std::endl;
}
void addElement(int element) override {
elements.push_back(element);
}
};
class Stack : public BaseContainer {
private:
std::vector elements;
public:
void printSize() const override {
std::cout << "Stack size: " << elements.size() << std::endl;
}
void addElement(int element) override {
elements.push_back(element);
}
};
class Queue : public BaseContainer {
private:
std::vector elements;
public:
void printSize() const override {
std::cout << "Queue size: " << elements.size() << std::endl;
}
void addElement(int element) override {
elements.push_back(element);
}
};
int main() {
Array arr;
Stack stack;
Queue queue;
BaseContainer* containers[] = {&arr, &stack, &queue};
for (auto container : containers) {
container->printSize();
container->addElement(42);
container->printSize();
std::cout << std::endl;
}
return 0;
}