Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

SortedList Class Template Reference

The following class defines a "sorted list" -- a singly linked list of list elements, arranged so that "Remove" always returns the smallest element. All types to be inserted onto a sorted list must have a "Compare" function defined: int Compare(T x, T y) returns -1 if x < y returns 0 if x == y returns 1 if x > y. More...

#include <list.h>

Inheritance diagram for SortedList::

List List of all members.

Public Methods

 SortedList (int(*comp)(T x, T y))
 ~SortedList ()
void Insert (T item)
 insert an item onto the list in sorted order. More...

void SanityCheck () const
 has this list been corrupted? More...

void SelfTest (T *p, int numEntries)
 verify module is working. More...


Private Methods

void Prepend (T item)
 *pre*pending has no meaning in a sorted list. More...

void Append (T item)
 *ap*pending has no meaning in a sorted list. More...


Private Attributes

int (* compare )(T x, T y)
 function for sorting list elements. More...


Detailed Description

template<class T> class SortedList

The following class defines a "sorted list" -- a singly linked list of list elements, arranged so that "Remove" always returns the smallest element. All types to be inserted onto a sorted list must have a "Compare" function defined: int Compare(T x, T y) returns -1 if x < y returns 0 if x == y returns 1 if x > y.

Definition at line 90 of file list.h.


Constructor & Destructor Documentation

template<class T>
SortedList<T>::SortedList<T> ( int(* comp)(T x, T y) ) [inline]
 

Definition at line 92 of file list.h.

template<class T>
SortedList<T>::~SortedList<T> ( ) [inline]
 

Definition at line 93 of file list.h.


Member Function Documentation

template<class T>
void SortedList<T>::Append ( T item ) [inline, private, virtual]
 

*ap*pending has no meaning in a sorted list.

Reimplemented from List.

Definition at line 106 of file list.h.

template<class T>
void SortedList<T>::Insert ( T item )
 

insert an item onto the list in sorted order.

SortedList::Insert Insert an "item" into a list, so that the list elements are sorted in increasing order.

Allocate a ListElement to keep track of the item. If the list is empty, then this will be the only element. Otherwise, walk through the list, one element at a time, to find where the new item should be placed.

"item" is the thing to put on the list.

Definition at line 232 of file list.cc.

Referenced by Append(), Prepend(), and SelfTest().

template<class T>
void SortedList<T>::Prepend ( T item ) [inline, private, virtual]
 

*pre*pending has no meaning in a sorted list.

Reimplemented from List.

Definition at line 104 of file list.h.

template<class T>
void SortedList<T>::SanityCheck ( ) const [virtual]
 

has this list been corrupted?

SortedList::SanityCheck Test whether this is still a legal sorted list.

Test: is the list sorted?

Reimplemented from List.

Definition at line 334 of file list.cc.

Referenced by SelfTest().

template<class T>
void SortedList<T>::SelfTest ( T * p,
int numEntries )
 

verify module is working.

SortedList::SelfTest Test whether this module is working.

Reimplemented from List.

Definition at line 354 of file list.cc.

Referenced by LibSelfTest().


Member Data Documentation

template<class T>
int(* SortedList<T>::compare)(T x, T y) [private]
 

function for sorting list elements.

Referenced by Insert(), SanityCheck(), and SelfTest().


The documentation for this class was generated from the following files:
Generated at Wed Jul 4 11:32:24 2001 for Nachos by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001