Introduction
In the previous post, I’ve talked about Queue. In this post, I’d like to extend it to make it more useful by adding several new methods.
Implementation
Based on the previous definition of Queue, we use one of C++’s characteristics——Inheritance to define ExtendedQueue(ExtendedQueue.hpp).
1 | class ExtendedQueue: public Queue { |
Noted that serve_and_retrieve() is actually a combination of serve() and retrieve().
full()
precondition: None.
postcondition: Return true if the ExtendedQueue is full; return false otherwise.
1 | template <class Queue_entry> |
clear()
precondition: None.
postcondition: All entries in the ExtendedQueue have been removed; it is now empty.
1 | template <class Queue_entry> |
size()
precondition: None.
postcondition: Return the number of entries in the ExtendedQueue.
1 | template <class Queue_entry> |
serve_and_retrieve(Queue_entry &item)
precondition: None.
postcondition: Return UnderFlow if the ExtendedQueue is empty. Otherwise remove and copy the item at the front of the ExtendedQueue to item and return Success.
1 | template <class Queue_entry> |
So far, I’ve gave a brief introduction of an entended queue. Please make sure that your each container written by yourself should be strictly tested before being used by another programme. Thank you!