Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#ifndef STACK_H
#define STACK_H
#include <exception>
#include <memory>
class Stack
{
private:
const int maxSize;
int numValues;
std::unique_ptr<char[]> stack;
public:
class Full: public std::exception
{
public:
virtual const char* what() const throw();
};
class Empty: public std::exception
{
public:
virtual const char* what() const throw();
};
/** Initialise the stack, maxSize is the maximum number of
values that can be stored in the stack at any time */
Stack( const int _maxSize );
~Stack();
/** Returns the number of values currently stored in the
stack */
int num_items() const;
/** Add value to the top of the stack, raises Stack::Full
exception if stack is full */
void push( char value );
/** Returns the value currently stored at the top of the
stack, raises Stack::Empty exception if stack is
empty */
char top();
/** Removes and returns the value currently stored at the
top of the stack, raises Stack::Empty exception if stack
is empty */
char pop();
};
#endif