Queue< ElemType > Class Template Reference

#include "queue.h"

List of all members.

Public Member Functions

 Queue ()
 ~Queue ()
int size ()
bool isEmpty ()
void enqueue (ElemType elem)
ElemType dequeue ()
ElemType peek ()
void clear ()
const Queueoperator= (const Queue &rhs)
 Queue (const Queue &rhs)

Classes

struct  cell


Detailed Description

template<typename ElemType>
class Queue< ElemType >

This interface defines a class that models a queue, or waiting line. It is a linear collection managed in first-in-first-out order. Values are added to the end and removed from the front. The queue operations are enqueue (add to end) and dequeue (remove from front). For maximum generality, the Queue is supplied as a class template. The client specializes the queue to hold values of a specific type, e.g. Queue<customerT> or Queue<string>, as needed


Constructor & Destructor Documentation

template<typename ElemType>
Queue< ElemType >::Queue (  ) 

The constructor initializes a new empty queue.

template<typename ElemType>
Queue< ElemType >::~Queue (  ) 

The destructor deallocates storage associated with this queue.

template<typename ElemType>
Queue< ElemType >::Queue ( const Queue< ElemType > &  rhs  ) 


Member Function Documentation

template<typename ElemType>
int Queue< ElemType >::size (  ) 

This member function returns the number of elements in this queue.

template<typename ElemType>
bool Queue< ElemType >::isEmpty (  ) 

This member function returns true if this queue contains no elements, false otherwise.

template<typename ElemType>
void Queue< ElemType >::enqueue ( ElemType  elem  ) 

This member function adds element to the end of this queue. That element becomes the last element in the queue. The queue's size increases by one.

template<typename ElemType>
ElemType Queue< ElemType >::dequeue (  ) 

This member function removes the front element from this queue and returns it. The front element is the one that was first enqueued. The queue's size decreases by one. This function raises an error if called on an empty queue.

template<typename ElemType>
ElemType Queue< ElemType >::peek (  ) 

This member function returns the value of front element in this queue, without removing it. The queue's size is unchanged. Raises an error if peek is called on an empty queue.

template<typename ElemType>
void Queue< ElemType >::clear (  ) 

This member function removes all elements from this queue. The queue is made empty and will have size() = 0.

template<typename ElemType>
const Queue< ElemType > & Queue< ElemType >::operator= ( const Queue< ElemType > &  rhs  ) 

This copy constructor and operator= are defined to make a deep copy, making it possible to pass/return queues by value and assign from one queue to another. The entire contents of the queue, including all elements, are copied. Each queue element is copied from the original queue to the copy using assignment (operator=). Making copies is generally avoided because of the expense and thus, queues are typically passed by reference, however, when a copy is needed, these operations are supported.


The documentation for this class was generated from the following file:
Generated on Mon Feb 12 23:30:08 2007 for CS 106B Libraries by  doxygen 1.5.1