Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote