//*****************************************************************************
// File: stack.cc
// Implementation of the long_stack.
//*****************************************************************************

#include <stdio.h>
#include <std.h>
#include "stack.h"

void long_stack::clear()
{
   s_node *temp;

   while (top != NULL) {
      temp = top->prev;
      delete top;
      top = temp;
   }
   stack_length = 0;
}


void long_stack::push(long item)
{
   s_node *temp = top;

   if ((top = new s_node) == NULL) {
      fprintf(stderr, "class int_stack: push: Out of memory.\n");
      exit(1);
   }
   top->info = item;
   top->prev = temp;
   stack_length++;
}


long long_stack::pop()
{
   s_node *temp;
   long item;

   if (stack_length == 0) {
      fprintf(stderr, "class long_stack: pop: Stack is empty.\n");
      exit(1);
   }
   temp = top->prev;
   item = top->info;
   delete top;
   top = temp;
   stack_length--;
   return item;
}
