Answered step by step
Verified Expert Solution
Question
1 Approved Answer
write it in c++ language // QueueLinked.h #ifndef QUEUE_H #define QUEUE_H #include using namespace std; template class Queue { public: // Constructor Queue(); //Desctructor ~Queue();
write it in c++ language // QueueLinked.h #ifndef QUEUE_H #define QUEUE_H #includeusing namespace std; template class Queue { public: // Constructor Queue(); //Desctructor ~Queue(); // Makes the queue to the empty state. void make_empty(); // Checks if the queue is empty. bool empty() const; // Inserts item at the end of the queue. void enqueue(const T& item) // Removes the element at the start of the queue. void dequeue(); // returns the front element const T& front_element() const; // Prints the elements of the queue. void print() const private: struct NodeType { T data; NodeType* next; NodeType(const T & d = T()): data(d) { next = nullptr; } }; NodeType* front; NodeType* back; }; #endif
// QueueLinked.cpp #include "QueueLinked.h" templateQueue ::Queue() { front = nullptr; back = nullptr; } // add other member functions // ....
You also can put the implementation of the Queue class template in Queue.h.
// QueueLinked.h #ifndef QUEUE_H #define QUEUE_H #includeusing namespace std; template class Queue { public: // Constructor Queue() { front = nullptr; back = nullptr; } // add other member functions // .... private: struct NodeType { T data; NodeType* next; NodeType(const T & d = T()): data(d) { next = nullptr; } }; NodeType* front; NodeType* back; }; #endif
- Define the Queue class template in the header file QueueLinked.h.
- Please read the comments carefully and implement the Queue class template.
You can implement the Queue class template in the seperate file QueueLinked.cpp.
- The main function is contained in the file lab05.cpp.
// lab05.cpp #include
The main function,#include "QueueLinked.h" #include "QueueLinked.cpp" // add if the interface and implementation are seperate int main() { .... } - Declare a queue which stores int values.
- Prompt the user to enter integers, enqueue the entered values, stop entering the integers when the user enter -1.
- Print the elements of queue.
- Prompt the user to enter a number k, and dequeue k values from the front of the queue.
- Print the elements of queue.
- Declare a queue which stores strings.
- Prompt the user to enter strings, enqueue the entered strings, stop entering the strings when the user enter exit.
- Print the elements of queue.
- Prompt the user to enter a number k, and dequeue k strings from the front of the queue.
- Print the elements of queue.
The expected result:
Enqueue positive numbers (enter -1 to stop): 1 2 3 4 5 6 7 8 9-1 print queue: 1, 2, 3, 4, 5, 6, 7, 8, 9, How many numbers to be removed from queue: 5 print queue: 6, 7, 8, 9, Enqueue string (enter exit to stop): abc def ghi jkl mno pqr exit print queue: abc, def, ghi, jkl, mno, pqr, How many strings to be removed from queue: 5 print queue: pqr,
Step 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