//----------------------------------------------------------------------
//  IMPLEMENTATION FILE (bstack.cpp)
//  This module exports an ADT for a bounded stack of integer values.
//  The stack bound is MAX_DEPTH.
//  Stack representation: a vector.
//----------------------------------------------------------------------
#include "bstack.h"

// Private members of class:
//     int data[MAX_DEPTH];   // Vector representing the stack
//     int top;               // Subscript of current top item (or -1 if
//                            //    stack is empty)
//
// CLASSINV:  -1 <= top < MAX_DEPTH

IntStack::IntStack()
    //..................................................................
    // Constructor
    // POST: top == -1
    //..................................................................
{
    top = -1;
}

Boolean IntStack::IsEmpty() const
    //..................................................................
    // POST: FCTVAL == (top == -1)
    //..................................................................
{
    return (top == -1);
}

Boolean IntStack::IsFull() const
    //..................................................................
    // POST: FCTVAL == (top == MAX_DEPTH-1)
    //..................................................................
{
    return (top == MAX_DEPTH-1);
}

void IntStack::Push( /* in */ int newItem )
    //..................................................................
    // PRE:  top < MAX_DEPTH-1  &&  Assigned(newItem)
    // POST: top == top<entry> + 1
    //    && data[top<entry>+1] == newItem
    //..................................................................
{
    data[++top] = newItem;
}

int IntStack::Top() const
    //..................................................................
    // PRE:  top >= 0
    // POST: FCTVAL == data[top]
    //..................................................................
{
    return data[top];
}

void IntStack::Pop()
    //..................................................................
    // PRE:  top<entry> >= 0
    // POST: top == top<entry> - 1
    //..................................................................
{
    top--;
}

