29 lines
477 B
C++

#ifndef EXMAPLE18_STACK_H
#define EXMAPLE18_STACK_H
typedef void* T;
class Stack {
private:
int top;
T* impl; // an array of pointers to void
public:
Stack(int n=5) : top(-1), impl(new T[n]) {
}
~Stack() {
delete[] impl;
}
bool empty() const {
return top == -1;
}
void push(T el) {
impl[++top] = el;
}
T pop() {
return impl[top--];
}
};
#endif //EXMAPLE18_STACK_H