Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This is what I have for my Node.h file, and im not sure how to implement concatenate and merge properly . class Node{ public: NodeT():
This is what I have for my Node.h file, and im not sure how to implement concatenate and merge properly .
class Node{
public:
NodeT(): data(0), next(nullptr){};
NodeT(int value) : data(value), next(nullptr) {};
NodeT(int value, NodeT* nd) : data(value), next(nd) {};
~NodeT() {};
//Attributes
int data;
NodeT* next;
};
This is what I have tried.
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 Queuer 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} Queue QueueT::concatenate(QueueT& qu, int n)const QueueT result; QueueT re = qu; int stop = 0; 1/while it is not empty, we want to for the size if(n > re.size()X{ throw std:: runtime_error("n is greater than a while(stop != n) { result.enqueue ( re.front->data); re.dequeue(); stop++; return result; //merge - returns a Queuet object that contains the //constant QueueT reference parameter Queuet QueueT::merge(const QueueT & qu) const{ Queuet result; NodeT* temp = front; //NodeT* first = qu. front; //Queuet qc = copyQueueT(qu); while (front != nullptr){ result.enqueue (temp->data); result.enqueue (qu.front->data); temp = front->next; qu.front = qu. front->next; return result; 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 Queuer 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} Queue QueueT::concatenate(QueueT& qu, int n)const QueueT result; QueueT re = qu; int stop = 0; 1/while it is not empty, we want to for the size if(n > re.size()X{ throw std:: runtime_error("n is greater than a while(stop != n) { result.enqueue ( re.front->data); re.dequeue(); stop++; return result; //merge - returns a Queuet object that contains the //constant QueueT reference parameter Queuet QueueT::merge(const QueueT & qu) const{ Queuet result; NodeT* temp = front; //NodeT* first = qu. front; //Queuet qc = copyQueueT(qu); while (front != nullptr){ result.enqueue (temp->data); result.enqueue (qu.front->data); temp = front->next; qu.front = qu. front->next; return resultStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started