template class queue A quiz on queue Bring your printout on Monday April 09 publ
ID: 3736448 • Letter: T
Question
template class queue A quiz on queue Bring your printout on Monday April 09 public . Implement queue push pop front . Check pre- II TYPEDEFS and MEMBER CONSTANTS typedef std::size t size type; typedef Item value_type static const size type CAPACITY 30 /I CONSTRUCTOR queue ); // MODIFICATION MEMBER FUNCTIONS void push(const Item& entry); void pop(); // CONSTANT MEMBER FUNCTIONS Item front() const; bool empty() const return (count 0) size type size() const return count; private Item data[CAPACITY]; /Circular array size type first; Index of item at front of the queue conditions if size type last; Index of item at rear of the queue size type count; I Total number of items in the queue / HELPER MEMBER FUNCTION size type next_index(size type i) const needed { return (1+1) % CAPACITY; }Explanation / Answer
Please find my defination:
queue::queue() {
first = 0;
rear = -1;
count = 0;
}
void queue::push(const Item& entry) {
if(count != CAPACITY) {
int t = next_index(rear);
data[t] = entry;
last = t;
}
}
Item queue::pop() {
Item t;
if(count != 0) {
t = data[first];
first = next_index(first);
}
return t;
}
Please upvote my naswer if it helped you!!!
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.