//EXAMPLE using Abstract Interface class Stack
#include <iostream.h>
class Stack {
public:
virtual void push (int) = 0;
virtual int pop () = 0;
virtual bool isFull () = 0;
virtual bool isEmpty () = 0;
virtual Stack* copy () = 0;
};
class FixedStack : public Stack {
private:
int *contents;
int top;
int max;
public:
FixedStack (int max) {
this->contents = new int[max];
this->top = 0;
this->max = max;
}
virtual void push (int x) {
contents[top++] = x;
}
virtual int pop () {
return contents[--top];
}
virtual bool isFull () {
return top == max;
}
virtual bool isEmpty () {
return top == 0;
}
virtual Stack* copy () {
FixedStack *result = new FixedStack (max);
for (int i=0; i< top; i++){
result->contents[i] = contents[i];
}
result->top = top;
return result;
}
};
main () {
Stack *s = new FixedStack (5);
s->push (1);
s->push (2);
s->push (3);
cout << "Popping: " << s->pop();
cout << ", " << s->pop ();
cout << ", " << s->pop () << endl;
}