The queue class below contains five public methods. The declaration of each meth
ID: 3871344 • Letter: T
Question
The queue class below contains five public methods. The declaration of each method is given without implementation. The private data and functions are not shown. Please add a new public member function flip with no parameters to the class queue. The flip function would reverse the order of the elements (i.e., integers) in queue.
class queue
{
public:
queue(); // constructor
bool empty() const; // returns true if the queue is empty
int size() const; // returns the number of items in the queue void enqueue
(int n); // adds item n to the end of the queue
int dequeue(); // removes and returns the item in the front of the queue
};
Explanation / Answer
void flip() {
if (size() != 0) {
int element = dequeue();
flip();
enqueue(element);
}
else {
return;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.