Question: A queue is also a linear structure which does not allow access to arbitrary elements stored in it. A queue has two entry points: front
A queue is also a linear structure which does not allow access to arbitrary elements stored in it. A queue has two entry points: front and rear. When an element is added, it is always added at the rear end. When an element is read or removed, it is always read/removed from the front of the queue. Queues are also known as FIFO (first-in-first-out) structures, which means that elements are removed and returned from a queue in the order in which they were inserted.
Using C++,could you please implement the functions in the following header file:
#ifndef QUEUE_H
#define QUEUE_H
#include "orderedContainer.h"
#include "linearStructure.h"
template
class Queue : public OrderedContainer
{
public:
/*
The constructor initializes the Queue with the
structure which will contain the elements. Remember to
make a deep copy of the input structure.
*/
Queue(LinearStructure
/*
Copy constructor
*/
Queue(const Queue
/*
Overloaded assignment operator.
*/
virtual Queue
/*
Destructor.
*/
virtual ~Queue();
/*
This function removes and returns the element
at the front of the Queue.
*/
virtual T remove();
/*
This function returns, but does NOT remove, the
element at the front of the queue.
*/
virtual T next();
/*
This function places the element sent in as a
parameter at the back of the Queue.
*/
virtual void insert(T el);
/*
This function reverses the order of the elements
in the queue. For example, if the stack contains the
elements w, x, y and z, where w is at the front (first element)
of the queue, then the queue should be z, y, x, w after the
reverse with z now being at the front of the queue.
*/
virtual void reverse();
};
#include "queue.cpp"
#endif
///////
OrderedContainer.h:
#ifndef ORDEREDCONTAINER_H
#define ORDEREDCONTAINER_H
#include "linearStructure.h"
template
class OrderedContainer
{
public:
/*
The constructor initializes the Container with the
structure passed in as a parameter. You will have to
make a copy of the LinearStructure as parties outside
of this class may have pointers to it still. The
elements added to the container must be stored in the
object to which dataStructure points.
*/
OrderedContainer(LinearStructure
/*
Copy constructor
*/
OrderedContainer(const OrderedContainer
/*
Overloaded assignment operator.
*/
virtual OrderedContainer
/*
Destructor.
*/
virtual ~OrderedContainer();
/*
Removes an element from the container. See subclasses
for more details.
*/
virtual T remove() = 0;
/*
Returns an element from the container. See subclasses
for more details.
*/
virtual T next() = 0;
/*
Inserts an element into the container. See subclasses
for more details.
*/
virtual void insert(T el) = 0;
/*
Returns true if the container is empty, and false
if the container contains elements.
*/
virtual bool isEmpty();
/*
This function reverses the order of the elements
in the container.
*/
virtual void reverse() = 0;
/*
Returns a pointer to the linear structure in which the elements
are contained.
*/
virtual LinearStructure
protected:
/*
A pointer to an object of type LinearStructure. This
structure should contain the elements inserted into
the container. This member should be initialized
in the constructor.
*/
LinearStructure
};
#include "orderedContainer.cpp"
#endif
///////
LinearStructure.h
#ifndef LINEARSTRUCTURE_H #define LINEARSTRUCTURE_H
#include
using namespace std;
template
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
