// array-based stack: int x[MAXSIZE]; int toS; AStack::AStack() { toS = -1; } void AStack::clear() { toS = -1; } bool AStack::isEmpty() const { return toS == -1; } // 0, 1, 2 MAXSIZE = 3 void AStack::push(const int& el) { if( toS < MAXSIZE-1) x[++toS] = el; else throw(stack_full_exception); } int AStack::pop() { if( toS >= 0) return x[toS--]; else throw(stack_empty_exception); } int AStack::peek() { int el = pop(); push(el); return el; }