Permalink
Cannot retrieve contributors at this time
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?
4003CEM-datastructs/queue.h
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
57 lines (45 sloc)
1.17 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef QUEUE_H | |
#define QUEUE_H | |
#include <exception> | |
#include <memory> | |
class Queue | |
{ | |
private: | |
const int maxSize; | |
int numValues; | |
std::unique_ptr<char[]> queue; | |
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 queue, maxSize is the maximum number of | |
values that can be stored in the queue at any time **/ | |
Queue( const int _maxSize ); | |
~Queue(); | |
/** Returns the number of values currently stored in the | |
queue **/ | |
int num_items() const; | |
/** Add value to the front of the queue, raises Queue::Full | |
exception is queue is full **/ | |
void push( char value ); | |
/** Returns the value currently stored at the front of the | |
queue, raises Queue::Empty exception is queue is | |
empty **/ | |
char front() const; | |
/** Returns the value currently stored at the back of the | |
queue, raises Queue.Empty exception if the queue is | |
empty **/ | |
char back() const; | |
/** Removes and returns the value currently stored at the | |
front of the queue, raises Queue::Empty exception is queue | |
is empty **/ | |
char pop(); | |
}; | |
#endif |