Question: C++ Project Create a templated Queue Class with a node based variant. The following is an example of the NodeQueue header file that will be
C++ Project
Create a templated Queue Class with a node based variant.
The following is an example of the NodeQueue header file that will be holding elements of type class DataType. This class should be templated.
class NodeQueue
{
public:
NodeQueue(); //Instantiates a new queue object with no elements(Nodes)
NodeQueue(int size, const DataType& value); //Instantiate a new queue object that dynamically allocates at instantiation to hold int size number of elements(Nodes) all //initialized to be equal to parameter value
NodeQueue(const NodeQueue& other); //Instantiate a new Queue object which is a seperate copy of the other queue object getting copied
~NodeQueue(); //Destroys the instance of the queue object
NodeQueue& operator = (const NodeQueue& other_nodeQueue); //Assigns new value to the calling of the queue object which is an exact copy of the other_nodeQueue object //passed as a parameter. Returns a reference to the calling object to be used for cascading operator =
DataType& front(); //Returns reference to front element of the Queue (Ensure that the queue is not empty)
const DataType& front() const;
DataType& back(); // Returns a reference to back element of the Queue. (Ensure that queue is not empty)
const DataType& back() const;
void push(const DataType& value); // inserts at the back of the queue an element of the given value
void pop(); //Removes front element of queue
int size() const; // Returns size of current Queue
bool empty() const; // Returns true if queue is empty
bool full() const; //Return true if queue is full
void clear(); //After function is called the queue will be considered empty
friend std::ostream& operator<< (std::ostream& os, const NodeQueue& nodeQueue); //(Template optional) This will output queue object (sequentially pop until final element)
private:
Node *m_front; //Templated node pointer type pointing to the first element of the queue
Node *m_back; // Templated node pointer type pointing to the last element of the queue
}
//The following is the Node class holding elements of type class DataType. This class should also be templated
class Node{
public:
Node();
Node(const DataType& data, Node* next = NULL);
DataType& getData;
const DataType& getData() const;
friend class NodeQueue;
private:
Node * m_next;
DataType m_data;
};
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
