/* Ylopoihsh stoibas me pinaka */

#include <iostream>
#include <new>
#include <exception>
#define DEFAULTSIZE 100

using namespace std;

class stackEmptyException: public exception
{
  	virtual const char* what() const throw(){
		return "Stack is empty";
	}

};

class stackFullException: public exception
{
  	virtual const char* what() const throw(){
		return "Stack is full";
	}

};


template <class T>
class ArrayStack{
  private:
	T * array; /* O pinakas ston opoio ulopoieitai h stoiba */
	int length; /* To plh8os twn stoixeion pou periexei h stoiba */
	int size; /* To mege8os ths stoibas (size <= length) */

  public:
	ArrayStack(int size = DEFAULTSIZE){
		this->size = size;
		array = new T[size];
		length = 0;
	}

	~ArrayStack(){
		delete [] array;
	}

	int getLength(){
		return length;
	}

	bool isEmpty (){
		return (length == 0);
	}

	bool isFull (){
		return (length == size);
	}

	T top(){
		if(length == 0){
			throw new stackEmptyException();
		}

		return array[length-1];
	}

	T pop(){
		T ret;

		if(length == 0){
			throw new stackEmptyException();
		}
		
		ret = array[length-1];
		length --;
		return ret;
	}

	void push (T data){
		if(length == size){
			throw new stackFullException();
		}

		length++;
		array[length - 1] = data;

		return;
	}
};
