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

Your Name: 14. (10 pts) Given the following Queue class template, write the func

ID: 3735904 • Letter: Y

Question

Your Name: 14. (10 pts) Given the following Queue class template, write the function template for the enqueue 0 TA's Name: function. Note: the queue is constructed by using an array allocated on the heap. template class Queue COMS public: Queue (int newSize = 0); ~Queue (); yes bool enqueue (T &newItem;) ; ACP bool dequeue (T & removedtem) ; lary bool isEmpty(); private: int mSize; // represents the number of items in the queue int mMaxSize; // must not exceed the max size of our allocated array T *mpFront; // will point to the beginning of contiguous memory on // the heap (an array) // Place your function template for enqueue () below. // Description: Copies the newItem to the tail of the queue. A successful insert increases the size by 1. 7/ Returns: true if the newItem was placed into the contiguous memory: false otherwise // Precondition: mpFront must already point to contiguous memory. 17 Errors: check that copying the newItem to the queue does not exceed the allocated array space; if it does, don't copy the item to the queue, and return false.

Explanation / Answer

template <class T>
bool Queue::enqueue(T &newItem)
{
if (!isEmpty())
{
    return false;
}
else
{
   mpFront[mSize] = newItem;
   mSize++;
    return true;
}
}

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