Question: You need to use C++ template to implement a Queue class using C++ vectors so that your queue class can store data of any type.

You need to use C++ template to implement a Queue class using C++ vectors so that your queue class can store data of any type. Since you use C++ vectors, you will not need to specify queue sizes. Your class should provide at least the following functions:

(1) top(), which returns the top of the queue;

(2) pop(), which returns the top of the queue and also remove it from the queue;

(3) push(), which inserts an element into the end of the queue;

(4) empty(), which returns whether the queue is empty.

Your main function needs to do the following:

(1) Instantiate a queue of integers; push integers 1, 2, 3, 4, 5, and 6 into the queue one by one, then pop all of them out and print out each number that you pop (which will be in the order of 1, 2, 3, 4, 5, and 6.

(2) Instantiate a queue of doubles; push doubles 0.1, 0.2, 0.3, 0.4, 0.5, and 0.6 into the queue one by one, then pop all of them out and print out each number that you pop (which will be in the order of 0.1, 0.2, 0.3, 0.4, 0.5, and 0.6.

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!