The C++Course provides a general introduction to programming in C++. It is based on A.B. Downey's book, How to Think Like a Computer Scientist. Click here for details. |
Home Queues and Priority Queues The Queue ADT | ||
See also: Queues and Priority Queues | ||
The Queue ADT
The queue ADT is defined by the following operations:
As far as our implementation goes, it does not matter what kind of object is in the Queue, so we can make it generic. Here is what the implementation looks like. class Queue {public: LinkedList list; Queue () { list = new List (); } bool empty () { return list.empty (); } void insert (Node* node) { list.addLast (node); } Node* remove () { return list.removeFirst (); } }; A queue object contains a single instance variable, which is the list that implements it. For each of the other methods, all we have to do is invoke one of the methods from the LinkedList class.
|
||
Home Queues and Priority Queues The Queue ADT |