MP4
Stacks and Queues
|
Queue class: represents a standard queue. More...
#include "queue.h"
Public Member Functions | |
void | enqueue (const T &newItem) |
Adds the parameter object to the back of the Queue. More... | |
T | dequeue () |
Removes the object at the front of the Queue, and returns it to the caller. More... | |
void | add (const T &theItem) |
Adds an element to the ordering structure. More... | |
T | remove () |
Removes an element from the ordering structure. More... | |
T | peek () |
Finds the object at the front of the Queue, and returns it to the caller. More... | |
bool | isEmpty () const |
Determines if the Queue is empty. More... | |
![]() | |
virtual | ~OrderingStructure () |
Destructor for the OrderingStructure. More... | |
Private Attributes | |
Stack< T > | inStack |
One of the two Stack objects you must use. More... | |
Stack< T > | outStack |
The other of the two Stack objects you must use. More... | |
Queue class: represents a standard queue.
Templated to hold elements of any type. You must only use the two private member Stacks as your storage space! You cannot create new private member variables to hold your objects! It is up to you to determine how to use them, however.
Your Queue class should have O(1) running time over n operations (amortized). There is an obvious solution that takes O(n) running time, but this will not recieve all of the available points.
You should not modify this file for the MP!
void Queue< T >::enqueue | ( | const T & | newItem | ) |
T Queue< T >::dequeue | ( | ) |
Removes the object at the front of the Queue, and returns it to the caller.
You may assume that this function is only called when the Queue is non-empty.
|
virtual |
Adds an element to the ordering structure.
Implements OrderingStructure< T >.
|
virtual |
Removes an element from the ordering structure.
Implements OrderingStructure< T >.
|
virtual |
Finds the object at the front of the Queue, and returns it to the caller.
Unlike pop(), this operation does not alter the queue. You may assume that this function is only called when the Queue is non-empty.
Unlike pop(), this operation does not alter the queue.
Implements OrderingStructure< T >.
|
virtual |
Determines if the Queue is empty.
Implements OrderingStructure< T >.
The other of the two Stack objects you must use.