//----------------------------------------------------------------------
//  IMPLEMENTATION FILE (cstack.cpp)
//  This module exports an ADT for a stack of characters.
//  Stack representation: a vector.
//----------------------------------------------------------------------
#include "cstack.h"

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

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

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

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

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

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

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

