#ifndef STACK_H
#define STACK_H

//#include "utility.h"

typedef char Stack_entry;

class Stack 
{
public:
	Stack();
	~Stack();
	bool empty() const;
	Error_code push(Stack_entry &item);
	Error_code pop();
	Error_code top(Stack_entry &item) const;
protected:
	Node *top_node;
};


//
Stack::Stack() // Default Constructor
{
	top_node = NULL;
}


Error_code Stack::pop()
/*
Post: The top of the Stack is removed.  If the Stack
      is empty the method returns underflow; otherwise it returns success.
*/
{
   Node *old_top = top_node;
   if (top_node == NULL) 
	   return underflow;
   top_node = old_top->next;
   delete old_top;
   return success;
}

Error_code Stack::top(Stack_entry &item) const
/*
Post: The data at the top of the Stack is returned via &item
If the Stack is empty the method returns underflow; 
otherwise it returns success.
*/
{
   if (top_node == NULL) 
	   return underflow;
   item = top_node->entry;
   
   return success;
}


Error_code Stack::push(Stack_entry &item)
{
   Node *new_top = new Node(item, top_node);
   if(new_top == NULL)
	   return overflow;
   top_node = new_top;
   return success;

}

bool Stack::empty() const
{
	/*if(top_node== NULL)
		return true;
	else
		return false;
		*/
	//return (top_node == NULL ? true : false);

	return top_node == NULL;

}



Stack::~Stack() //  Destructor

//Post: The Stack is cleared.

{
   while(!empty())
	   pop();
}


#endif 