Stack : ADT. LIFO Last In First Out. top of stack. bottom of stack

Stack : ADT LIFO – Last In First Out top of stack 5 4 3 2 1 bottom of stack 1 Stack : Operations ! ! ! ! ! ! makeEmpty isEmpty isFull push pop ...
Author: Erik Mills
3 downloads 1 Views 285KB Size
Stack : ADT LIFO – Last In First Out

top of stack

5 4 3 2 1

bottom of stack

1

Stack : Operations ! ! ! ! ! !

makeEmpty isEmpty isFull push pop top

2

3

// File: AbstractStack.h #ifndef ABSTRACT_STACK_H #define ABSTRACT_STACK_H template class AbstractStack { public: virtual void makeEmpty() =0; virtual bool isEmpty() const =0; virtual bool isFull() const =0; virtual void push(const E& e) =0; virtual void pop() =0; virtual E top() const =0;
 }; #endif

4

// File: ArrayStack.h #ifndef ARRAY_STACK_H #define ARRAY_STACK_H
 #include "AbstractStack.h" template class ArrayStack : public 
 AbstractStack { private: int size; int topIndex; E* stack;

5

void copyElements(
 const ArrayStack& o); void releaseElements(); public: ArrayStack(const int size = 100); ArrayStack(const ArrayStack& o); virtual ~ArrayStack(); virtual const ArrayStack& operator 
 =(const ArrayStack& o);

6

virtual virtual virtual virtual virtual virtual };

void makeEmpty(); bool isEmpty() const; bool isFull() const; void push(const E& e); void pop(); E top() const 
 throw (logic_error);


#include "ArrayStack.cpp" 


#endif

7

// File: ArrayStack.cpp template void ArrayStack::copyElements(
 const ArrayStack& o) { size = o.size; topIndex = o.topIndex; stack = new E [size]; for (int i = 0; i

Suggest Documents