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
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