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* c);

/*

Copy constructor

*/

Queue(const Queue& other);

/*

Overloaded assignment operator.

*/

virtual Queue& operator=(const Queue& other);

/*

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* c);

/*

Copy constructor

*/

OrderedContainer(const OrderedContainer& other);

/*

Overloaded assignment operator.

*/

virtual OrderedContainer& operator=(const OrderedContainer& other);

/*

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* getImplementation();

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* dataStructure;

};

#include "orderedContainer.cpp"

#endif

///////

LinearStructure.h

#ifndef LINEARSTRUCTURE_H #define LINEARSTRUCTURE_H

#include

using namespace std;

template class LinearStructure { public: virtual ~LinearStructure(){} virtual LinearStructure* clone() = 0; virtual void insert(int index, T element) = 0; virtual T remove(int index) = 0; virtual T get(int index) const = 0; virtual bool isEmpty() = 0; virtual void clear() = 0; }; #endif

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!