#include <List.h>
Public Member Functions | |
| List () | |
| Default List constructor. | |
| List (List Const &L) | |
| List copy constructor. | |
| List (Type i_) | |
| List constructor for a list of length 1. | |
| List (Type i1_, Type i2_) | |
| List constructor for a list of length 2. | |
| List (Type i1_, Type i2_, Type i3_) | |
| List constructor for a list of length 3. | |
| List (Type i1_, Type i2_, Type i3_, Type i4_) | |
| List constructor for a list of length 4. | |
| List (Type i1_, Type i2_, Type i3_, Type i4_, Type i5_) | |
| List constructor for a list of length 5. | |
| List (Type i1_, Type i2_, Type i3_, Type i4_, Type i5_, Type i6_) | |
| List constructor for a list of length 6. | |
| List (Type i1_, Type i2_, Type i3_, Type i4_, Type i5_, Type i6_, Type i7_) | |
| List constructor for a list of length 7. | |
| List (Type i1_, Type i2_, Type i3_, Type i4_, Type i5_, Type i6_, Type i7_, Type i8_) | |
| List constructor for a list of length 8. | |
| List (Type i1_, Type i2_, Type i3_, Type i4_, Type i5_, Type i6_, Type i7_, Type i8_, Type i9_) | |
| List constructor for a list of length 9. | |
| List (Type i1_, Type i2_, Type i3_, Type i4_, Type i5_, Type i6_, Type i7_, Type i8_, Type i9_, Type i10_) | |
| List constructor for a list of length 10. | |
| List (Type i1_, Type i2_, Type i3_, Type i4_, Type i5_, Type i6_, Type i7_, Type i8_, Type i9_, Type i10_, Type i11_) | |
| List constructor for a list of length 11. | |
| List (Type i1_, Type i2_, Type i3_, Type i4_, Type i5_, Type i6_, Type i7_, Type i8_, Type i9_, Type i10_, Type i11_, Type i12_) | |
| List constructor for a list of length 12. | |
| List (Type i1_, Type i2_, Type i3_, Type i4_, Type i5_, Type i6_, Type i7_, Type i8_, Type i9_, Type i10_, Type i11_, Type i12_, Type i13_) | |
| List constructor for a list of length 13. | |
| List (Type i1_, Type i2_, Type i3_, Type i4_, Type i5_, Type i6_, Type i7_, Type i8_, Type i9_, Type i10_, Type i11_, Type i12_, Type i13_, Type i14_) | |
| List constructor for a list of length 14. | |
| List (Type i1_, Type i2_, Type i3_, Type i4_, Type i5_, Type i6_, Type i7_, Type i8_, Type i9_, Type i10_, Type i11_, Type i12_, Type i13_, Type i14_, Type i15_) | |
| List constructor for a list of length 15. | |
| List (Type i1_, Type i2_, Type i3_, Type i4_, Type i5_, Type i6_, Type i7_, Type i8_, Type i9_, Type i10_, Type i11_, Type i12_, Type i13_, Type i14_, Type i15_, Type i16_, Type i17_, Type i18_, Type i19_, Type i20_, Type i21_, Type i22_) | |
| List constructor for a list of length 16. | |
| ~List () | |
| Default List destructor. | |
| Bool | operator== (Const List &L) |
| List equality operator. | |
| Bool | operator!= (Const List &L) |
| List inequality operator. | |
| List & | operator+= (Const List &L) |
| List concatenation/copy operator, joins lists together. | |
| List | operator+ (Const List &L) |
| List concatenation operator, joins lists together. | |
| List & | operator= (Const List &L) |
| List assignment operator. | |
| Type & | operator[] (Integer elem) |
| List indexing operator. | |
| List & | operator+= (Const Type x) |
| List increment operator, adds Integer to value of all elements of list. | |
| List & | operator-= (Const Type x) |
| List decrement operator, subtracts Integer to value from all elements of list. | |
| List & | operator+ (Const Type x) |
| List addition operator, adds Integer to value of all elements of list. | |
| List & | operator- (Const Type x) |
| List subtraction operator, subtracts Integer to value from all elements of list. | |
| List & | operator * (Const Type x) |
| List multiplication operator, multiplies Integer by value of all elements of list. | |
| List & | operator/ (Const Type x) |
| List division operator, multiplies Integer by value of all elements of list. | |
| Void | print (String s=0) |
| List print method. | |
| Void | SetListSize (Integer n) |
| Preset list to a particular size. | |
| Void | checkSize (Integer len) |
| List range checking method. | |
| Integer | length () |
| List length method. | |
| Type | max () |
| List max method. | |
| Integer | maxPos () |
| List maxPos method. | |
| Type | min () |
| List min method. | |
| Integer | minPos () |
| List minPos method. | |
| Void | rotate (Integer n, Integer i=0) |
| Rotate list by n elements from position i. | |
| Void | transpose (Type t, Type lim) |
| Offset values of list elements by t modulo lim. | |
| Void | invert (Type lim) |
| Invert values of list elements at limit. | |
| Void | retrograde () |
| Retrograde values of list elements. | |
Friends | |
| ostream & | operator<< (ostream &os, Const List &r) |
| Print list to output stream. | |
| Void | adjustSize (Integer len, List &r) |
| Lists are auto-ranging in size. | |
| istream & | operator>> (istream &is, List &r) |
| Read a list from the input stream. | |
List automatically adjusts its length to accommodate whatever index is provided, therefore, no initial bounds must be provided when the list is created. Simply indexing an element of the list causes it to come into being, initialized to 0 (for reference), or to the value being assigned.
Definition at line 32 of file List.h.
Default List constructor.
Definition at line 85 of file List.h.
Referenced by List< Type >::operator *(), and List< Type >::operator+().
| List< Type >::List | ( | Type | i1_, | |
| Type | i2_, | |||
| Type | i3_, | |||
| Type | i4_, | |||
| Type | i5_, | |||
| Type | i6_, | |||
| Type | i7_, | |||
| Type | i8_, | |||
| Type | i9_, | |||
| Type | i10_ | |||
| ) | [inline] |
List constructor for a list of length 10.
Definition at line 169 of file List.h.
00169 { 00170 m_val = new Type [ m_len = 10 ]; 00171 m_val[0] = i1_; m_val[1] = i2_; m_val[2] = i3_; m_val[3] = i4_; m_val[4] = i5_; m_val[5] = i6_; m_val[6] = i7_; m_val[7] = i8_; 00172 m_val[8] = i9_; m_val[9] = i10_; 00173 }
| List< Type >::List | ( | Type | i1_, | |
| Type | i2_, | |||
| Type | i3_, | |||
| Type | i4_, | |||
| Type | i5_, | |||
| Type | i6_, | |||
| Type | i7_, | |||
| Type | i8_, | |||
| Type | i9_, | |||
| Type | i10_, | |||
| Type | i11_ | |||
| ) | [inline] |
List constructor for a list of length 11.
Definition at line 176 of file List.h.
00176 { 00177 m_val = new Type [ m_len = 11 ]; 00178 m_val[0] = i1_; m_val[1] = i2_; m_val[2] = i3_; m_val[3] = i4_; m_val[4] = i5_; m_val[5] = i6_; m_val[6] = i7_; m_val[7] = i8_; 00179 m_val[8] = i9_; m_val[9] = i10_; m_val[10] = i11_; 00180 }
| List< Type >::List | ( | Type | i1_, | |
| Type | i2_, | |||
| Type | i3_, | |||
| Type | i4_, | |||
| Type | i5_, | |||
| Type | i6_, | |||
| Type | i7_, | |||
| Type | i8_, | |||
| Type | i9_, | |||
| Type | i10_, | |||
| Type | i11_, | |||
| Type | i12_ | |||
| ) | [inline] |
List constructor for a list of length 12.
Definition at line 183 of file List.h.
00183 { 00184 m_val = new Type [ m_len = 12 ]; 00185 m_val[0] = i1_; m_val[1] = i2_; m_val[2] = i3_; m_val[3] = i4_; m_val[4] = i5_; m_val[5] = i6_; m_val[6] = i7_; m_val[7] = i8_; 00186 m_val[8] = i9_; m_val[9] = i10_; m_val[10] = i11_; m_val[11] = i12_; 00187 }
| List< Type >::List | ( | Type | i1_, | |
| Type | i2_, | |||
| Type | i3_, | |||
| Type | i4_, | |||
| Type | i5_, | |||
| Type | i6_, | |||
| Type | i7_, | |||
| Type | i8_, | |||
| Type | i9_, | |||
| Type | i10_, | |||
| Type | i11_, | |||
| Type | i12_, | |||
| Type | i13_ | |||
| ) | [inline] |
List constructor for a list of length 13.
Definition at line 190 of file List.h.
00190 { 00191 m_val = new Type [ m_len = 13 ]; 00192 m_val[0] = i1_; m_val[1] = i2_; m_val[2] = i3_; m_val[3] = i4_; m_val[4] = i5_; m_val[5] = i6_; m_val[6] = i7_; m_val[7] = i8_; 00193 m_val[8] = i9_; m_val[9] = i10_; m_val[10] = i11_; m_val[11] = i12_; m_val[12] = i13_; 00194 }
| List< Type >::List | ( | Type | i1_, | |
| Type | i2_, | |||
| Type | i3_, | |||
| Type | i4_, | |||
| Type | i5_, | |||
| Type | i6_, | |||
| Type | i7_, | |||
| Type | i8_, | |||
| Type | i9_, | |||
| Type | i10_, | |||
| Type | i11_, | |||
| Type | i12_, | |||
| Type | i13_, | |||
| Type | i14_ | |||
| ) | [inline] |
List constructor for a list of length 14.
Definition at line 197 of file List.h.
00197 { 00198 m_val = new Type [ m_len = 14 ]; 00199 m_val[0] = i1_; m_val[1] = i2_; m_val[2] = i3_; m_val[3] = i4_; m_val[4] = i5_; m_val[5] = i6_; m_val[6] = i7_; m_val[7] = i8_; 00200 m_val[8] = i9_; m_val[9] = i10_; m_val[10] = i11_; m_val[11] = i12_; m_val[12] = i13_; m_val[13] = i14_; 00201 }
| List< Type >::List | ( | Type | i1_, | |
| Type | i2_, | |||
| Type | i3_, | |||
| Type | i4_, | |||
| Type | i5_, | |||
| Type | i6_, | |||
| Type | i7_, | |||
| Type | i8_, | |||
| Type | i9_, | |||
| Type | i10_, | |||
| Type | i11_, | |||
| Type | i12_, | |||
| Type | i13_, | |||
| Type | i14_, | |||
| Type | i15_ | |||
| ) | [inline] |
List constructor for a list of length 15.
Definition at line 204 of file List.h.
00204 { 00205 m_val = new Type [ m_len = 15 ]; 00206 m_val[0] = i1_; m_val[1] = i2_; m_val[2] = i3_; m_val[3] = i4_; m_val[4] = i5_; m_val[5] = i6_; m_val[6] = i7_; m_val[7] = i8_; 00207 m_val[8] = i9_; m_val[9] = i10_; m_val[10] = i11_; m_val[11] = i12_; m_val[12] = i13_; m_val[13] = i14_; m_val[14] = i15_; 00208 }
| List< Type >::List | ( | Type | i1_, | |
| Type | i2_, | |||
| Type | i3_, | |||
| Type | i4_, | |||
| Type | i5_, | |||
| Type | i6_, | |||
| Type | i7_, | |||
| Type | i8_, | |||
| Type | i9_, | |||
| Type | i10_, | |||
| Type | i11_, | |||
| Type | i12_, | |||
| Type | i13_, | |||
| Type | i14_, | |||
| Type | i15_, | |||
| Type | i16_, | |||
| Type | i17_, | |||
| Type | i18_, | |||
| Type | i19_, | |||
| Type | i20_, | |||
| Type | i21_, | |||
| Type | i22_ | |||
| ) | [inline] |
List constructor for a list of length 16.
Definition at line 211 of file List.h.
00212 { 00213 m_val = new Type [ m_len = 22 ]; 00214 m_val[0] = i1_; m_val[1] = i2_; m_val[2] = i3_; m_val[3] = i4_; m_val[4] = i5_; m_val[5] = i6_; m_val[6] = i7_; m_val[7] = i8_; 00215 m_val[8] = i9_; m_val[9] = i10_; m_val[10] = i11_; m_val[11] = i12_; m_val[12] = i13_; m_val[13] = i14_; m_val[14] = i15_; 00216 m_val[15] = i16_; m_val[16] = i17_; m_val[17] = i18_; m_val[18] = i19_; m_val[19] = i20_; m_val[20] = i21_; m_val[21] = i22_; 00217 }
List range checking method.
If the list is empty, the list is created. If the list exists, and it is less than length len, then it is reallocated to contain len elements.
| len | Size to reallocate list, if necessary. |
Definition at line 448 of file List.h.
Referenced by List< Type >::operator[]().
00448 { 00449 If (m_val == 0) 00450 m_val = new Type [ m_len = len+1 ]; 00451 Else If (m_len <= len) { 00452 m_len = len+1; 00453 m_val = (Type*) realloc( m_val, m_len * sizeof(Type)); 00454 } 00455 }
| Void List< Type >::invert | ( | Type | lim | ) | [inline] |
List length method.
Definition at line 459 of file List.h.
References Return.
Referenced by Invert(), List< Type >::invert(), List< Type >::operator!=(), List< Type >::operator==(), List< Type >::retrograde(), List< Type >::rotate(), Transpose(), and List< Type >::transpose().
00459 { 00460 Return m_len; 00461 }
| Type List< Type >::max | ( | ) | [inline] |
List max method.
Definition at line 465 of file List.h.
Referenced by Max(), and List< Type >::maxPos().
00465 { 00466 assert(m_len > 0); 00467 Type max = m_val[0]; 00468 For ( Integer i = 1; i < m_len; i++ ) 00469 max = m_val[i] < max ? max : m_val[i]; 00470 Return max; 00471 }
List maxPos method.
Definition at line 476 of file List.h.
References For, If, List< Type >::max(), and Return.
00476 { 00477 assert(m_len > 0); 00478 Type max = m_val[0]; 00479 Integer mp = 0; 00480 For ( Integer i = 1; i < m_len; i++ ) { 00481 If ( m_val[i] > max ) { 00482 max = m_val[i]; 00483 mp = i; 00484 } 00485 } 00486 Return mp; 00487 }
| Type List< Type >::min | ( | ) | [inline] |
List min method.
Definition at line 491 of file List.h.
Referenced by Min(), and List< Type >::minPos().
00491 { 00492 assert(m_len > 0); 00493 Type min = m_val[0]; 00494 For ( Integer i = 1; i < m_len; i++ ) 00495 min = m_val[i] < min ? m_val[i] : min; 00496 Return min; 00497 }
List minPos method.
Definition at line 502 of file List.h.
References For, If, List< Type >::min(), and Return.
00502 { 00503 assert(m_len > 0); 00504 Type min = m_val[0]; 00505 Integer mp = 0; 00506 For ( Integer i = 1; i < m_len; i++ ) { 00507 If ( m_val[i] < min ) { 00508 min = m_val[i]; 00509 mp = i; 00510 } 00511 } 00512 Return mp; 00513 }
List multiplication operator, multiplies Integer by value of all elements of list.
| x | Integer value to multiply by all elements of list |
Definition at line 336 of file List.h.
References For, List< Type >::List(), List< Type >::m_val, and Return.
00336 { 00337 List* t = new List (*this); 00338 *t = *this; // copy this 00339 For ( Integer i = 0; i < m_len; i++ ) 00340 t->m_val[i] *= x; 00341 Return( *t ); 00342 }
List inequality operator.
Definition at line 240 of file List.h.
References For, If, List< Type >::length(), Return, and True.
00240 { 00241 If ( L.m_len != m_len ) 00242 Return(True); 00243 Integer cnt = 0; 00244 For( Integer i = 0; i < length(); i++ ) { 00245 If ( L.m_val[i] == m_val[i] ) 00246 cnt++; 00247 } 00248 Return( cnt != m_len ); 00249 }
List addition operator, adds Integer to value of all elements of list.
| x | Integer value to add to all elements of list |
Definition at line 314 of file List.h.
References For, List< Type >::List(), List< Type >::m_val, and Return.
00314 { 00315 List* t = new List (*this); 00316 *t = *this; // copy this 00317 For ( Integer i = 0; i < m_len; i++ ) 00318 t->m_val[i] += x; 00319 Return( *t ); 00320 }
List concatenation/copy operator, joins lists together.
| L | List to concatenate to this |
Definition at line 254 of file List.h.
References Return.
00254 { 00255 m_val = (Type*) realloc( m_val, (m_len + L.m_len) * sizeof(Type)); 00256 memcpy(&m_val[m_len], L.m_val, sizeof(Type) * L.m_len); 00257 m_len += L.m_len; 00258 Return( *this ); 00259 }
List subtraction operator, subtracts Integer to value from all elements of list.
| x | Integer value to subtract from all elements of list |
Definition at line 325 of file List.h.
References For, List< Type >::m_val, and Return.
00325 { 00326 List* t = new List [ m_len ]; 00327 *t = *this; // copy this 00328 For ( Integer i = 0; i < m_len; i++ ) 00329 t->m_val[i] -= x; 00330 Return( *t ); 00331 }
List decrement operator, subtracts Integer to value from all elements of list.
| x | Integer value to subtract from all elements of list |
Definition at line 305 of file List.h.
00305 { 00306 For ( Integer i = 0; i < m_len; i++ ) 00307 m_val[i] -= x; 00308 Return( *this ); 00309 }
List division operator, multiplies Integer by value of all elements of list.
| x | Integer value to divide by all elements of list |
Definition at line 347 of file List.h.
References For, List< Type >::m_val, and Return.
00347 { 00348 List* t = new List [ m_len ]; 00349 *t = *this; // copy this 00350 For ( Integer i = 0; i < m_len; i++ ) 00351 t->m_val[i] /= x; 00352 Return( *t ); 00353 }
List assignment operator.
| L | List to assign to this |
Definition at line 273 of file List.h.
00273 { 00274 If (this == &L) 00275 Return *this; 00276 If (m_val != 0) 00277 delete [] m_val; 00278 m_val = new Type [ m_len = L.m_len ]; 00279 memcpy(m_val, L.m_val, sizeof(Type) * m_len); 00280 Return( *this ); 00281 }
List equality operator.
Two lists are equal if they have the same length and all elements in corresponding positions are identical.
Definition at line 229 of file List.h.
References False, For, If, List< Type >::length(), Return, and True.
00229 { 00230 If ( L.m_len != m_len ) 00231 Return(False); 00232 For( Integer i = 0; i < length(); i++ ) { 00233 If ( L.m_val[i] != m_val[i] ) 00234 Return( False ); 00235 } 00236 Return( True ); 00237 }
List indexing operator.
Performs range checking.
| elem | Integer index of list element to return |
Definition at line 287 of file List.h.
References List< Type >::checkSize(), and Return.
List print method.
| s | String value to print at head of list. |
Definition at line 419 of file List.h.
00419 { 00420 If (s) 00421 cout << s; 00422 cout << "{ "; 00423 cout.precision(2); 00424 For (Integer i = 0; i < m_len-1; i++) 00425 cout << m_val[i] << ", "; 00426 cout << m_val[m_len-1]; 00427 cout << " }" << endl; 00428 }
| Void List< Type >::retrograde | ( | ) | [inline] |
Retrograde values of list elements.
Definition at line 548 of file List.h.
References For, and List< Type >::length().
00548 { 00549 Integer n = length( ); 00550 Type* t = new Type [ m_len ]; 00551 memcpy(t, m_val, sizeof(Type) * m_len); 00552 For ( Integer i = 0; i < n; i = i + 1 ) 00553 m_val[ i ] = t[ n - i - 1 ]; 00554 }
Rotate list by n elements from position i.
| i | Starting position, usually set to 0. | |
| n | Number of elements to rotate. Positive n rotates counterclockwise; negative n rotates clockwise. |
Definition at line 518 of file List.h.
References If, List< Type >::length(), Mod(), and PosMod().
00518 { 00519 n = Mod( n, length() ); // constrain rotation to length of list 00520 Type x = m_val[ i ]; // store f[ i ] for use after recursion 00521 If ( i < length() - 1 ) // reached the end? 00522 rotate( n, i+1 ); // no, set up next element via recursion 00523 // We continue from here when the recursion unwinds 00524 Integer pos = PosMod( i+n, length() ); // index list modulo its length 00525 m_val[ pos ] = x; // assign value of x saved above 00526 }
| Void List< Type >::transpose | ( | Type | t, | |
| Type | lim | |||
| ) | [inline] |
Offset values of list elements by t modulo lim.
Note: uses PosMod() to preserve elements within the interval 0..lim.
| t | Transposition value | |
| lim | Transposition limit |
Definition at line 532 of file List.h.
References For, List< Type >::length(), and PosMod().
00532 { 00533 For ( Integer i = 0; i < length(); i = i + 1 ) { 00534 Type x = m_val[ i ] + t; 00535 m_val[ i ] = PosMod(x, lim); 00536 } 00537 }
Lists are auto-ranging in size.
This function reallocates the memory for a list to match its length requirements.
Definition at line 53 of file List.h.
00053 { 00054 If (r.m_val == 0) { 00055 r.m_val = new Type [ r.m_len = len+1 ]; 00056 } Else If (r.m_len <= len) { 00057 r.m_len = len+1; 00058 r.m_val = (Type*) realloc( r.m_val, r.m_len * sizeof(Type)); 00059 } 00060 }
| ostream& operator<< | ( | ostream & | os, | |
| Const List< Type > & | r | |||
| ) | [friend] |
Print list to output stream.
List is printed as '{' <elem0> ',' <elem1> ',' ... '}'
Definition at line 36 of file List.h.
00036 { 00037 If (r.m_len > 0) 00038 os << "("; 00039 for (Integer i = 0; i < r.m_len; i++) { 00040 os << r.m_val[i]; 00041 If (i != r.m_len-1) 00042 os << ", "; 00043 Else 00044 os << ")"; 00045 } 00046 os << endl; 00047 Return os; 00048 }
| istream& operator>> | ( | istream & | is, | |
| List< Type > & | r | |||
| ) | [friend] |
Read a list from the input stream.
List is read as '(' <elem0> ',' <elem1> ',' ... ')'
Definition at line 64 of file List.h.
00064 { 00065 char ch; 00066 Type t; 00067 Integer len = 0; 00068 is >> ch; 00069 If (ch != '{' And ch != '(') 00070 Return is; 00071 While (is >> t >> ch And ch == ',') { 00072 adjustSize(len, r); 00073 r.m_val[len++] = t; 00074 } 00075 adjustSize(len, r); 00076 r.m_val[len++] = t; 00077 assert( ch == '}' || ch == ')'); 00078 Return is; 00079 }
1.4.7