Question: Code in C++ Can someone complete the addBack, removeFront, and the removeBack portion so it can compile. Following these guidelines: Class Description Your class should

Code in C++

Can someone complete the addBack, removeFront, and the removeBack portion so it can compile. Following these guidelines:

Class Description Your class should be named QueueT and should support these operations: Creating an empty queue Inserting a value Removing a value Finding the size of the queue Printing the contents of the queue Adding the contents of one queue to the end of another Merging the contents of two queues into a third, new, queue Class Attributes Your class should be implemented using a linked list and should have the following private member variables A pointer to a NodeT that represents the front of the queue A pointer to a NodeT that represents the back of the queue An int that records the current size of the queue (i.e. the number of values in the queue) Queue Public Methods You must implement a QueueT template class to store data of any type. The queue must be implemented using a singly linked list of Nodes, where NodeT is a class that you also implement. Note that the enqeue and deqeue methods should be implemented in constant time. The QueueT class should implement the following public methods: constructor creates an empty queue copy constructor a constructor that creates a deep copy of its constant QueueT reference parameter destructor deallocates dynamic memory allocated by the queue operator= overloads the assignment operator for QueueT (deep) copies its constant QueueT reference parameter into the calling object and returns a reference to the calling object after de-allocating any dynamic memory associated with the original contents of the calling object; if the calling object is equal to the parameter the operator should not copy it enqueue inserts its template type parameter at the back of the queue dequeue removes and returns the value at the front of the queue; if the queue is empty throws a runtime_error (this error class is defined in the stdexcept library file) print prints the contents of the queue, one value per line, from front to back empty returns true if the queue is empty, false otherwise size returns the number of items stored in the queue concatenate has two parameters, a QueueT reference and an integer (referred to as n in this description) adds the first n values stored in its QueueT parameter to the end of the calling object, the resulting queue therefore contains its original contents order unchanged followed by the first n values of the parameter queue in their original order; the values added to the calling object should be removed from the parameter; both queue's sizes should be adjusted as appropriate; if n is greater than the size of the parameter a runtime_error should be thrown and no changes made to either queue merge returns a QueueT object that contains the contents of the calling object and its constant QueueT reference parameter, the resulting queue should start with the first value in the calling object, followed by the first value in the parameter, subsequent values should be copied in order from the two queues alternating between them; no changes should be made to either the calling object or the parameter; example: calling object = {a,b,c,d,e}, parameter = {r,s,t}, result = {a,r,b,s,c,t,d,e} getFront returns a pointer to the node at the front of the queue. This method is provided to you here: NodeT* getFront() { return front; }; Its purpose is to allow us to directly access your queue's linked list for testing. It is not something a working class should include since allowing access to the internal structure of a class is not good design. Note that if you called your pointer to the node at the front of the queue something other than "front" you will need to change the method given above to return the correct attribute. Additional Notes The calling object should be made constant for any method where the calling object's attribute values should not change You may implement helper methods if you wish (for example, you might want to implement a deep copy method that can be used by the copy constructor and the overloaded assignment operator) Your class may include other private attributes that you deem necessary Method parameters and return values are noted (and highlighted) in the method descriptions you must not add additional parameters to the methods; if the method description does not mention a parameter it does not have one, similarly if no return value is mentioned the method is void (or a constructor or destructor) The parameter type for enqeue and the return type of deqeue should be your template variable see the implementation notes near the end of this document NodeT Class The NodeT class should have a template type attribute for its data and a pointer to the next NodeT in the list. These attributes must be made public and must be named data and next. The class should have constructors as you see fit I would suggest one with two parameters that sets the data and next NodeT (pointer) to the parameter values and one with a single template type parameter that sets its next pointer to a nullptr. Your NodeT class must be written in your QueueT.h file, above and outside the QueueT class definition.The way I would suggest approaching writing the assignment is something like this: 1. Create a new project with a file that contains a main function that you will use for testing; add a new QueueT class to the project; then compile and run your project to make sure it is set up correctly 2. Write your NodeT and QueueT classes as regular (non-template) classes that store a base type, like an int, testing methods as you implement them 3. Write, and thoroughly test, one or two functions at a time. 4. Once your class is working perfectly convert it into a template class Note that Bjarne Stroustrup recommends implementing template classes by first implementing a non-template class version - and I suspect his advice is worth following! File Structure Template classes are often contained in a single .h file as there are compilation issues with breaking them down into separate files, and this is what I want you to do for this assignment. I still want you to keep the implementation separate from the interface as much as possible within this structure, so your method implementations should appear below your QueueT class definition. Your .h file will therefore have this general structure.

#include using namespace std;

class QNode { public: int data; QNode* next; QNode* prev; QNode(int d) { data = d; } friend class Queue; };

class Queue { public:

//constructor Queue() { //initialize the size to a value of 0 size = 0; //initialize our header and tailer by allocating memory upon creation and sets //initial value of our data to 0 using our QNode constructor header = new QNode(0); tailer = new QNode(0); header->prev = NULL; header->next = tailer; tailer->prev = header; tailer->next = NULL; }

//destructor ~Queue() { while (!empty()) { delete header; delete tailer; } }

bool empty() { if (size == 0) { return true; } else { return false; } } int front() { //return our headers position at the front of the list return tailer->prev->data; } int back() { //return our tailers positioned element return tailer->prev->data; } void add(QNode* node, QNode* AddedNode) { AddedNode->next = node; AddedNode->prev = node->prev; node->prev->next = AddedNode; node->prev = AddedNode;

}

void addFront(int x) { //we not only create the new node but our constructer immediatly puts our //desired value into the node by passing it our x that is given when we call //to add a node, so if we pass 10 in then the new node will have 10 as its data value QNode* newNode = new QNode(x); add(header->next, newNode);//call the add function above this to add the node } void addBack(int x) {

} void removeFront() {

} void removeBack() {

} private: QNode* header; QNode* tailer; int size;

};

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!