// P.J. Waskiewicz  4/15/1998
// File: Tstack.cc
// Implementation of the stack ADT using a linked list

#include "Tstack.h"

template <class T>
Stack <T>::Stack()
{
  head = 0;
}

template <class T>
void Stack<T>::push(T e)
{
  Link addedNode = new Node;
  assert(addedNode);
  addedNode->data = e;
  addedNode->next = head;
  head = addedNode;
}

template <class T>
T Stack<T>::pop()
{
  // Check to see if empty list
  assert(head);
  T e;
  Link deleteNode(head);
  e = head->data;

  // link the head to the next node in the list
  head = head->next;

  // delete the node
  delete deleteNode;

  return e;
}

template <class T>
T Stack<T>::top()
{
  return head->data;
}

template <class T>
bool Stack<T>::isEmpty()
{
  // If head equals 0, the list is empty, and this is true

  return head == 0;
}