Header File for Stack ADT - Array Implementation


#ifndef STACKARR_H
#define STACKARR_H

// *********************************************************
// Header file Stackarr.h for the ADT stack.
// Array-based implementation.
// *********************************************************
const int MAX_STACK = 50;
typedef char stackItemType;

class Stack
{
public:
// constructors and destructor:
   Stack();  // default constructor
             // copy constructor and destructor are supplied by the compiler

// stack operations:
   int isEmpty();
   // Determines whether a stack is empty.
   // Precondition: None.
   // Postcondition: Returns true if stack is empty; otherwise returns false.

   int push(stackItemType NewItem);
   // Adds an item to the top of a stack.
   // Precondition: NewItem is the item to be added.
   // Postcondition: If insertion was successful, NewItem is on the top of 
   // the stack and push returns true; otherwise push returns false.

   int pop();
   // Removes the top of a stack.
   // Precondition: None.
   // Postcondition: If the stack was not empty, the item that was added 
   // most recently is removed and pop returns true. However, if the stack 
   // was empty, deletion is impossible and pop returns false.

   int pop(stackItemType& StackTop);
   // Retrieves and removes the top of a stack.
   // Precondition: None.
   // Postcondition: If the stack was not empty, StackTop contains the item 
   // that was added most recently, the item is removed, and pop returns 
   // true. However, if the stack was empty, deletion is impossible, StackTop 
   // is unchanged, and pop returns false.

   int top(stackItemType& StackTop);
   // Retrieves the top of a stack.
   // Precondition: None.
   // Postcondition: If the stack was not empty, StackTop contains the item 
   // that was added most recently and top returns true. However, if the 
   // stack was empty, the operation fails, StackTop is unchanged, and pop 
   // returns false. The stack is unchanged.

private:
   stackItemType Items[MAX_STACK];  // array of stack items
   int           Top;               // index to top of stack
};  // end Stack class

#endif

// End of header file.


Email Me | Office Hours | My Home Page | Department Home | MCC Home Page