60 likes | 187 Views
Link Lists. CS-240/CS-341. Comparison of STL Containers. List Operations. Constructors: list<T> L; construct L as an empty list list<T> L(n) construct L as a list to contain n elements list<T> L(n,initv) construct L as a list of n elements each set to initv
E N D
Link Lists CS-240/CS-341
List Operations Constructors: list<T> L; construct L as an empty list list<T> L(n) construct L as a list to contain n elements list<T> L(n,initv) construct L as a list of n elements each set to initv list<T> L(fptr,lptr) construct L as a list to contain copies of elements in locations fptr thru lprt
List operations L.empty( ) return true if list contains no elements L.size( ) return number of values contained in the list L.push_back(v) append v at the end of the list, list becomes one longer L.push_front(v) insert v in front of the lists first element, list becomes one longer L.insert(pos,v) insert v at iterator position pos, return an iterator pointing to it L.insert(pos,n,v) insert n copies of v at iterator position pos L.insert(pos,fprt,lptr) insert copies of all elements in range fptr to lptr at iterator position pos L.pop_back( ) erase list’s last element L.pop_front( ) erase list’s first element L.erase(pos) erase the value at iterator position pos L.erase(pos1, pos2) erase all values from iterator position pos1 ti iterator position pos2 L.remove(v) erase all elements in list that match value v
List operations L.unique( ) replace all occurrences of a repeating sequence with a single occurrence of the sequence L.front( ) return a reference to the list’s first element L.back( ) return a reference to the list’s last element L.begin( ) return an iterator positioned at list’s first element L.end( ) return an iterator positioned at list’s last element L.rbegin( ) return a reverse iterator positioned at list’s last element L.rend( ) return a reverse iterator positioned one element before lists first element L.sort( ) sort lists elements (using <) L1.merge(L2) merge ans sort elements of L2 into L1; l2 ends up empty L1.splice(pos, L2) move all elements in L@ to iterator position pos of L1 L1.splice(to, L2, from) move element in L2 at iterator position from into L1 iterator position pos
List operations L1.swap(L2) swap the contents of the two lists L1=L2 pure assignment L1= =L2 return true if and only if L1 contains the same items as L2 and in the same order L1 < L2 return true if and only if L1 is lexicographically less than L2