#include <SList.hpp>
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 | |
| SLink * | head |
| SLink * | tail |
| SLink * | curr |
| ULONG | pos |
| ULONG | nbElements |
Definition at line 14 of file SList.hpp.
|
|
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 } |
|
|
|
|
|
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 }
|
|
|
|
|
|
|
|
|
|
|
|
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 }
|
|
|
Definition at line 70 of file SList.cpp. 00071 {
00072 append( item );
00073 }
|
|
|
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 }
|
|
|
Definition at line 127 of file SList.cpp. 00128 {
00129 return pos;
00130 }
|
|
|
|
|
|
|
|
|
|
|
|
Definition at line 176 of file SList.cpp. 00177 {
00178 return ( (curr != NULL) && (curr->next != NULL) );
00179 }
|
|
|
|
|
|
Definition at line 94 of file SList.cpp. 00095 {
00096 if (curr != NULL)
00097 {
00098 curr = curr->next;
00099 pos++;
00100 }
00101 }
|
|
|
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 }
|
|
|
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 }
|
|
|
Definition at line 43 of file SList.cpp. 00044 {
00045 curr = head;
00046 pos = 0;
00047 }
|
|
|
|
|
|
|
|
|
Definition at line 122 of file SList.cpp. 00123 {
00124 return nbElements;
00125 }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1.2.11.1 written by Dimitri van Heesch,
© 1997-2001