Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

SList Class Reference

WARNING: curr->next is the OFFICIAL current element ! /// This is to avoid prev(), when adding or removing elements ! /////////////////////////////////////////////////////////////////////////////. More...

#include <SList.hpp>

List of all members.

Public Methods

 SList ()
virtual ~SList ()
void clear ()
void insert (Elem item)
void append (Elem item)
Elem remove ()
void setFirst ()
void next ()
void prev ()
ULONG length () const
void setPos (ULONG pos)
void setValue (Elem item)
Elem currValue () const
Elem getValue () const
bool isEmpty () const
bool isInList () const
long find (Elem item)
void display ()
long getPos () const
long size () const
__inline void enqueue (Elem item)
__inline Elem dequeue ()

Private Attributes

SLinkhead
SLinktail
SLinkcurr
ULONG pos
ULONG nbElements


Detailed Description

WARNING: curr->next is the OFFICIAL current element ! /// This is to avoid prev(), when adding or removing elements ! /////////////////////////////////////////////////////////////////////////////.

Definition at line 14 of file SList.hpp.


Constructor & Destructor Documentation

__inline SList::SList  
 

WARNING: curr->next is the OFFICIAL current element ! /// This is to avoid prev(), when adding or removing elements ! /////////////////////////////////////////////////////////////////////////////.

Definition at line 13 of file SList.cpp.

00014  : nbElements( 0 ), pos( 0 )
00015 {
00016   head = tail = curr = new SLink();       // Create header node (NULL, NULL)
00017 }

SList::~SList   [virtual]
 

Definition at line 19 of file SList.cpp.

00020 {
00021   while( head != NULL )                   // Return links to freelist storage
00022   {
00023     curr = head;
00024     head = head->next;
00025     delete curr;
00026   }
00027 }


Member Function Documentation

__inline void SList::append Elem    item
 

Definition at line 63 of file SList.cpp.

Referenced by enqueue().

00064 {
00065   curr = tail = tail->next = new SLink( item, NULL );
00066   nbElements++;
00067   pos++;
00068 }

void SList::clear  
 

Definition at line 29 of file SList.cpp.

00030 {
00031   while( head->next != NULL )             // Return links to free store
00032   {
00033     curr       = head->next;              //   (keep header node)
00034     head->next = curr->next;
00035     delete curr;
00036   }
00037 
00038   curr = tail = head;                     // Reinitialize
00039   pos  = 0;
00040   nbElements = 0;
00041 }

Elem SList::currValue   const
 

Definition at line 164 of file SList.cpp.

00165 {
00166   assert( isInList() ); 
00167   return curr->next->element; 
00168 }

__inline Elem SList::dequeue  
 

Definition at line 75 of file SList.cpp.

00076 {
00077   curr = head;
00078   return remove();
00079 }

void SList::display  
 

Definition at line 213 of file SList.cpp.

00214 {
00215   if ( curr == head )  return;   // Empty List
00216   
00217   SLink* temp = curr;
00218   curr = head->next;
00219 
00220   printf( "===========================================\n" );
00221 
00222   while ( curr != NULL )             // Stop if we reach the end
00223   {
00224     printf( "%d \t", curr->element );
00225 
00226     if ( curr->next == NULL ) 
00227     {
00228       printf( "NULL \n" );
00229     } 
00230     else 
00231     {
00232       printf( "%d \n", curr->next->element );
00233     }
00234   
00235     curr = curr->next;
00236   }
00237 
00238   printf( "===========================================\n" );
00239 
00240   curr = temp;
00241 }

__inline void SList::enqueue Elem    item
 

Definition at line 70 of file SList.cpp.

00071 {
00072   append( item );
00073 }

long SList::find Elem    item
 

Definition at line 182 of file SList.cpp.

00183 {
00184   assert( !isEmpty() ); 
00185 
00186   SLink* temp = curr;
00187   ULONG  counter = 0;
00188 
00189   if ( curr == head  ||  curr == NULL ) 
00190   {
00191     curr = head->next;
00192     pos = 0;
00193   }
00194 
00195   for ( ; isInList(); curr = curr->next, pos++ ) 
00196   {
00197     if ( curr->element == item ) 
00198     {
00199       return pos;
00200     }
00201   }
00202 
00203   curr = temp;
00204   return -1;                              // Not found
00205 }

long SList::getPos   const
 

Definition at line 127 of file SList.cpp.

00128 {
00129   return pos;
00130 }

Elem SList::getValue   const
 

Definition at line 170 of file SList.cpp.

00171 {
00172   assert( isInList() ); 
00173   return curr->next->element; 
00174 }

void SList::insert Elem    item
 

Definition at line 50 of file SList.cpp.

00051 {
00052   assert( curr != NULL );                     // Must be pointing to list Elem
00053   curr->next = new SLink( item, curr->next );
00054 
00055   if ( tail == curr )                         // Appended new Elem
00056   {
00057     tail = curr->next;
00058   }
00059 
00060   nbElements++;
00061 }

__inline bool SList::isEmpty   const
 

Definition at line 207 of file SList.cpp.

00208 {
00209   return ( head->next == NULL || nbElements < 1 );
00210 }

__inline bool SList::isInList   const
 

Definition at line 176 of file SList.cpp.

00177 {
00178   return ( (curr != NULL)  &&  (curr->next != NULL) );
00179 }

ULONG SList::length   const
 

Definition at line 133 of file SList.cpp.

00134 {
00135   register ULONG cnt = 0;
00136   SLink* temp = head->next;
00137 
00138   for ( ; temp != NULL; temp = temp->next )
00139   {
00140      cnt++;                        // Count the number of Elems
00141   }
00142 
00143   return cnt;
00144 }

__inline void SList::next  
 

Definition at line 94 of file SList.cpp.

00095 {
00096   if (curr != NULL) 
00097   {
00098     curr = curr->next;
00099     pos++;
00100   }
00101 }

void SList::prev  
 

Definition at line 104 of file SList.cpp.

00105 {
00106   SLink* temp = head;
00107   if ((curr == NULL) || (curr == head))   // No previous Elem
00108   {
00109     curr = NULL;
00110     return;                               // So, just return
00111   }
00112 
00113   while( ( temp != NULL ) && ( temp->next != curr ) ) 
00114   {
00115     temp = temp->next;
00116   }
00117 
00118   curr = temp;
00119   pos--;
00120 }

Elem SList::remove  
 

Definition at line 81 of file SList.cpp.

00082 {
00083   assert( isInList() );                   // Must be valid position
00084   Elem   temp  = curr->next->element;     // Remember value
00085   SLink* ltemp = curr->next;              // Remember link node
00086   curr->next   = ltemp->next;             // Remove from list
00087   if (tail == ltemp) tail = curr;         // Removed last: set tail
00088   delete ltemp;                           // Send link to free store
00089 
00090   nbElements--;
00091   return temp;                            // Return value removed
00092 }

void SList::setFirst  
 

Definition at line 43 of file SList.cpp.

00044 {
00045   curr = head; 
00046   pos  = 0;
00047 }

void SList::setPos ULONG    p
 

Definition at line 146 of file SList.cpp.

00147 {
00148   curr = head;
00149   register ULONG i = 0;
00150   pos = 0;
00151 
00152   for( ; ( curr != NULL ) && ( i < p ); i++, pos++ )
00153   {
00154     curr = curr->next;
00155   }
00156 }

void SList::setValue Elem    val
 

Definition at line 158 of file SList.cpp.

00159 {
00160   assert( isInList() ); 
00161   curr->next->element = val; 
00162 }

long SList::size   const
 

Definition at line 122 of file SList.cpp.

00123 {
00124   return nbElements;
00125 }


Member Data Documentation

SLink* SList::curr [private]
 

Definition at line 46 of file SList.hpp.

SLink* SList::head [private]
 

Definition at line 44 of file SList.hpp.

ULONG SList::nbElements [private]
 

Definition at line 49 of file SList.hpp.

ULONG SList::pos [private]
 

Definition at line 48 of file SList.hpp.

SLink* SList::tail [private]
 

Definition at line 45 of file SList.hpp.


The documentation for this class was generated from the following files:
Generated on Sun Oct 14 18:49:40 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001