/* This is the header file for the Stack library.

-----------------------------------------------------------------*/

#ifndef STACK
#define STACK

#include <assert.h>

#include "LinkedList.h"

#include "Boolean.h"

class Stack : private LinkedList
{

 public:

  /* --- Class Constructor ---

     Precondition:  A stack has been defined.
     Postcondition: The stack has been constructed as an 
                      empty stack.
   ---------------------------------------------------------------*/

   Stack(void) : LinkedList() 
   {}


   /* --- Copy Constructor ---

     Precondition:  The compiler needs a copy of a Stack S.
     Receive:       S, the Stack to be copied
     Postcondition: The Stack containing this function is
                      a copy of S.
   ---------------------------------------------------------------*/

   Stack(const Stack& S) : LinkedList(S) 
   {}


   /* --- Is the Stack empty? ---

     Return: True iff the Stack containing this function is empty
   ---------------------------------------------------------------*/

   Boolean Empty(void) const
   { return (Length() == 0); }


   /* --- Is the Stack full? ---

     Return: True iff the Stack containing this function is full
   ---------------------------------------------------------------*/

   Boolean Full(void) const
   { return False; }     // a run-time allocated stack is "never" full


  /* --- Add an element to the stack ---

     Receive: Elem, the Element to be added
     Return:  The Stack containing this function, with Elem
                added at its top
   ---------------------------------------------------------------*/

   void Push(const ListElement& Elem)
   { Insert(Elem, Stack::Beginning); }// prepend Elem to the stack


   /* --- Remove the most-recently added element from the stack. ---

      Return: Elem, the top (most recently added) element
              The Stack containing this function, with Elem
                removed
   ---------------------------------------------------------------*/


   void Pop(ListElement& Elem)
   {
      assert(Length() > 0);      // check that stack isn't empty
      Elem = First->Data;        // return first node's Data via Elem
      Delete(Stack::Beginning);  // remove top node
   }
};

#endif
