Answered step by step
Verified Expert Solution
Link Copied!

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 #include  using 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" template  Queue::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 #include  using 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  #include "QueueLinked.h" #include "QueueLinked.cpp" // add if the interface and implementation are seperate int main() { .... } 
    The main function,
    1. Declare a queue which stores int values.
    2. Prompt the user to enter integers, enqueue the entered values, stop entering the integers when the user enter -1.
    3. Print the elements of queue.
    4. Prompt the user to enter a number k, and dequeue k values from the front of the queue.
    5. Print the elements of queue.
    6. Declare a queue which stores strings.
    7. Prompt the user to enter strings, enqueue the entered strings, stop entering the strings when the user enter exit.
    8. Print the elements of queue.
    9. Prompt the user to enter a number k, and dequeue k strings from the front of the queue.
    10. 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Handbook Of Database Security Applications And Trends

Authors: Michael Gertz, Sushil Jajodia

1st Edition

1441943056, 978-1441943057

More Books

Students also viewed these Databases questions

Question

Why does corporate governance influence company value?

Answered: 1 week ago

Question

Compute the mean and variance of (a) 1 0 tdB(t) (b) 1 0 t2 d B(t)

Answered: 1 week ago

Question

explain the need for human resource strategies in organisations

Answered: 1 week ago

Question

describe the stages involved in human resource planning

Answered: 1 week ago