MP4
Stacks and Queues
Queue< T > Class Template Reference

Queue class: represents a standard queue. More...

#include "queue.h"

+ Inheritance diagram for Queue< T >:
+ Collaboration diagram for Queue< T >:

Public Member Functions

void enqueue (const T &newItem)
 Adds the parameter object to the back of the Queue. More...
 
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...
 
remove ()
 Removes an element from the ordering structure. More...
 
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...
 
- Public Member Functions inherited from OrderingStructure< T >
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...
 

Detailed Description

template<class T>
class Queue< T >

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!

Author
CS 225 course staff
Date
Spring 2007
Author
Daniel Hoodin
Date
Spring 2008
Author
Chase Geigle
Date
Fall 2012

Member Function Documentation

template<class T >
void Queue< T >::enqueue ( const T &  newItem)

Adds the parameter object to the back of the Queue.

Note
This fuction should have O(1) behavior over n operations!
Parameters
newItemobject to be added to the Queue.
newItemobject to be added to the Queue.
Todo:
Your code here!
template<class T >
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.

Note
This function should have O(1) behavior over n operations!
Returns
The item that used to be at the front of the Queue.
The item that used to be at the front of the Queue.
Todo:
Your code here! You will need to replace the following line.
template<class T >
void Queue< T >::add ( const T &  theItem)
virtual

Adds an element to the ordering structure.

See also
OrderingStructure::add()
Todo:
Your code here! Hint: this function should call a Queue function to add the element to the Queue.

Implements OrderingStructure< T >.

template<class T >
T Queue< T >::remove ( )
virtual

Removes an element from the ordering structure.

See also
OrderingStructure::remove()
Todo:
Your code here! Hint: this function should call a Queue function to remove an element from the Queue and return it. You will need to replace the following line.

Implements OrderingStructure< T >.

template<class T >
T Queue< T >::peek ( )
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.

Note
This function should have O(1) behavior over n operations!
Returns
The item at the front of the queue.

Unlike pop(), this operation does not alter the queue.

Returns
The item at the front of the queue.
Todo:
Your code here! You will need to replace the following line.

Implements OrderingStructure< T >.

template<class T >
bool Queue< T >::isEmpty ( ) const
virtual

Determines if the Queue is empty.

Note
This function should have O(1) behavior over n operations!
Returns
bool which is true if the Queue is empty, false otherwise.
bool which is true if the Queue is empty, false otherwise.
Todo:
Your code here! You will need to replace the following line.

Implements OrderingStructure< T >.

Member Data Documentation

template<class T >
Stack<T> Queue< T >::inStack
private

One of the two Stack objects you must use.

template<class T >
Stack<T> Queue< T >::outStack
private

The other of the two Stack objects you must use.


The documentation for this class was generated from the following files: