/* Filename:  lststack.cpp

   Programmer:  Br. David Carlson

   Date:  August 8, 1998

   Modified:  June 7, 1999 to use exceptions.

   Last Modified:  December 23, 2001

   This file implements the functions of the LstStackClass found in
   LstStack.h.
*/

#include "lststack.h"


/* Given:  Nothing (other than the implicit LstStackClass object).
   Task:   To check whether this object is empty.
   Return: true if it is empty, false otherwise.
*/
bool LstStackClass::Empty(void) const
   {
   return List.Empty();   // Note the use of 2 different Empty functions!
   }


/* Given:  Item   A data item.
   Task:   To push item onto the stack (the implicit object).
   Return: Nothing directly, but the implicit object is modified.
*/
void LstStackClass::Push(const ItemType & Item)
   {
   try
      {
      List.InsertFront(Item);
      }
   catch(char * Str)
      {
      cout << "Error: could not push -- " << Str << endl;
      }
   }


/* Given:  Nothing.
   Task:   To pop the top item from the stack (the implicit object).
   Return: Item   The item popped from the stack.
*/
void LstStackClass::Pop(ItemType & Item)
   {
   try
      {
      Item = List.RemoveFront();   // assumes that = works on this type
      }
   catch(int Num)
      {
      cout << "Error: could not remove -- " << endl;
      }
   }


