Home / Expert Answers / Computer Science / code-in-c-get-started-write-a-class-template-for-a-linked-list-implementation-of-a-queue-the-que-pa761

(Solved): code in c++ get started. Write a class template for a linked list implementation of a queue. The que ...



code in c++
get started. Write a class template for a linked list implementation of a queue. The queue must have the same functions menti
get started. Write a class template for a linked list implementation of a queue. The queue must have the same functions mentioned in the queue ADT on the slides, except for the function that empties out the queue. It must use smart pointers. The private section shall only have two data members, a front pointer and back pointer. You must place the struct definition for the Node above the class definition. When writing each class function, be sure to consider: (1) if it will work for different possible states of the queue (empty, one node, many nodes), and ( 2 ) make sure the front and back pointers are set correctly for each case. Always consider what the state of your data members should be upon completion of a class function. Add an additional function, printQueue, just for testing the queue. I used the code: void printqueue( ) \{ shared_ptr> ptr( front); while ( ptr I= nu1lptr) \{ cout \( \ll \) ptr->info \( \ll " \cdots " ; \) ptr \( =p t r->n e x t ; \) \} cout \( \ll \) "nullptr" \( \ll \) end 1 ; \} a driver called "testqueue" used to test the queue. Write your data structure so that you can use the supplied driver without modifying the driver. You should get the following output when using the driver: Queue is empty Queue is no longer empty \( 1 \rightarrow \) nullptr \( 1 \rightarrow 2 \rightarrow \) nullptr first peek: 1 first dequeue: 1 \( 2 \rightarrow \) nullptr second dequeue: 2 nullptr Can no longer dequeue Can no longer peek Queue is empty again \( 3 \rightarrow 4 \rightarrow 5 \rightarrow \) nullptr 1020


We have an Answer from Expert

View Expert Answer

Expert Answer


#include using namespace std; struct QNode { int data; QNode* next; QNode(int d) { data = d; next = NULL; } }; struct Queue { QNode *f
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe