STL List doubly linked list

Source: Internet
Author: User
List Introduction

A list is a generalization container for a doubly linked list whose data elements can be strung into a logical linear table through a linked list pointer. Unlike vector and deque containers with linear table sequential storage structures, element insertion and deletion in any position in a list doubly linked list has an efficient time complexity O (1) for the constant order algorithm. Low query efficiency.
List Function Create a List objectList (), the constructor is the default invocation method for list (const a &a = A ()), such as:list<int> l;   List (size_type N) For example: List <int> L (10); The construct contains 10 int elements linked list L with an initial value of 0.   List (size_type N, const t& value) For example: List <double> L (10, 9.3); Constructs a linked list L with 10 double elements with an initial value of 9.3. List (List const list&), copy functions such as:list<double> L2 (L); List (inputiterator first, inputinterator last)//copy interval [first, end] For example: int iarray[] = {11, 22, 33}; List<int> L (IArray, iarray+3);traversal access of elementsCannot use "[]", only iterators.
The forward traversal of the element iterator begin () iterator end () For example: List<int>::iterator I, iend;  Iend = V.end (); for (i = V.begin (), j = 0; I! = Iend; i++, J + +) cout << "[" << J << "]=" << *i << Endl; The inverse traversal of the element reverse_iterator Rbegin () reverse_iterator rend () uses the same method as aboveinsertion of elementsvoid Push_front (const t& x) inserts void push_back (const t&) at the first of the list; Insert the tail of the list, for example: L.push_back (44); Iterator Insert (iterator pos, const t& x) is inserted at POS positiondeletion of elementsvoid Pop_front () removes the first element void Pop_back () removes the last element iterator erase (iterator POS) deletes the POS element iterator erase (iterator fir St, iterator last) removes an element of the interval [first, last) void clear () Removes all elements void remove (const t& value) and deletes all elements that are equal to value remove_if (bool function (t& Element)) The parameter of the function is a function, is a return value of bool, the parameter is a function of the element type to delete the condition satisfies the element (will traverse through the list)
exchange of Listvoid Swap (List &)merge of Listvoid Splice (iterator position, List &x) inserts the list x into the current list's position position, and the list object x is emptied void splice (iterator position, Lis t &, iterator i) inserts the value of another linked list from I into the current list list position, removes the inserted element from the original linked list void splice (iterator position, list &, ITER Ator Ibegin, iterator iend)
Inserts the value of the other linked list from Ibegin to iend into the current list list position, removes the inserted element from the original linked list of void merge (list &x) and merges the list object X's linked list into the current list link list. and empty the list of the x when merging, according to the current element one by one comparison and copied to the current listlist Element ProcessingL.sort () Merges the list L to sort, for example: C1.sort ();  Default from small to large c1.sort (great<int> ()); From large to small L. Unique ()
The list L is excluded from continuous elements, for example: L Before: 6 8 6 6 6 9 13 6 call Unique () after: 6 8 6 9 for 6 l.unique (bool Function (t& item1, t& item2)) Write your own comparison function
other functions of the listAssign (): Reallocate value void Assign (size_type n, const t& u);  Resets the list to contain n elements, the initial value is U void assign (Inputiterator first, Inputiterator last); Resets the list to the interval [first, last) front (): Returns the reference to the first element back (): Returns the reference to the last element begin (): A pointer to the first element (iterator) End (): A pointer that returns the next position of the last element
Size (): Gets the length of the list resize (): Change the length of the list reverse (): Reverse linked listReference Articles

STL List Baidu Encyclopedia C + + STL List Usage Summary
STL slist single-linked list "STL" List basics (examples of function details)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.