Question: Implement a template class Queue as defined by the following skeleton: template class Queue { private: NodeType * front; // It points to the front

Implement a template class Queue as defined by the following skeleton: template class Queue { private: NodeType* front; // It points to the front of a singly-linked list NodeType* rear; // It points to the end of a singly-linked list public: Queue( ); // default constructor: Queue is created and empty Queue(const Queue &x); // copy constructor: implicitly called // for a deep copy void MakeEmpty(); // Queue is made empty; you should deallocate all // the nodes of the linked list bool IsEmpty( ); // test if the queue is empty bool IsFull( ); // test if the queue is full; assume MAXITEM=5 int length( ); // return the number of elements in the queue void Print( ); // print the value of all elements in the queue in the sequence // from the front to rear void Enqueue(ItemType x); // insert x to the rear of the queue // Precondition: the queue is not full void Dequeue(ItemType &x); // delete the element from the front of the queue // Precondition: the queue is not empty ~Queue(); // Destructor: memory for the dynamic array needs to be deallocated }; In you main( ) routine, you need to test your class in the following cases: QueueIntQueue; int x; IntQueue.MakeEmpty(); IntQueue.Dequeue(x); IntQueue.Enqueue(10); IntQueue.Enqueue(20); IntQueue.Enqueue(30); IntQueue.Enqueue(40); cout << "int length 3 = " << IntQueue.length() << endl; IntQueue.Dequeue(x); cout << "int length 4 = " << IntQueue.length() << endl; cout << The int queue contains: << endl; IntQueue.Print(); if(IntQueue.IsFull() == false) cout << The int queue is not full ! << endl; else cout << The int queue is full ! << endl; QueueFloatQueue; string y; FloatQueue.MakeEmpty(); FloatQueue.Dequeue(y); FloatQueue.Enqueue(bob); cout << "float length 3 = " << FloatQueue.length() << endl; FloatQueue.Enqueue(john); cout << "float length 4 = " << FloatQueue.length() << endl; FloatQueue.Enqueue(dan); FloatQueue.Dequeue(y); cout << The float queue contains: << endl; FloatQueue.Print(); Queue FloatQueue2 = FloatQueue; cout << The float queue 2 contains: << endl; FloatQueue2.Print(); FloatQueue.MakeEmpty(); cout << The float queue 3 contains: << endl; FloatQueue2.Print();

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!