1 / 6

Link Lists

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

gala
Download Presentation

Link Lists

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Link Lists CS-240/CS-341

  2. Comparison of STL Containers

  3. 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

  4. 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

  5. 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

  6. 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

More Related