/* File: stack.C

   Implementation of a LIFO stack which is derived
   from our list ADT
*/

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


/* default constructor */
Stack::Stack() {
   /* Do nothing, List constructor is called already */
}


/* destructor */
Stack::~Stack() {
   /* Do nothing, List destructor is called already */
}


/* put data on top of the stack */
void Stack::Push(data x) {
   Prepend(x) ;
}


/* pop data off top of stack */
data Stack::Pop() {
   position pos ;
   data x ;

   pos = FirstPos() ;
   x = ItemAt(pos) ;
   Delete(pos) ;
   return x; 
}


/* return top of the stack */
data Stack::Top() {
   
   return ItemAt(FirstPos()) ;
}


/* Is the stack empty? 1=Yes, 0=No */
int Stack::IsEmpty() {

   if (Count() == 0) return 1 ;
   return 0 ;
}


/* Number of items in the stack */
int Stack::Depth() {

   /* count field is protected not private, therefore still accessible */
   return count ;  
}


/* Allow access to Print from List class */
void Stack::Print() {
   
    List::Print() ;   /* infinite recursion without "List::" */ 
}

