A list is a linear list structure whose data is composed of several nodes, each of which includes a
The block (that is, the actual stored data), a precursor pointer, and a rear-drive pointer. It does not need to assign the specified
Memory size and can be scaled arbitrarily because it is stored in a noncontiguous memory space, and is indicated by the
The needle links the ordered elements together.
Because of its structural reasons, List random retrieval performance is very bad, because it is not like vector that
To find the address of an element directly, but to find it in order from scratch, so that the target element is later
Its retrieval time is longer. The retrieval time is proportional to the position of the target element.
Although the speed of random retrieval is not fast enough, it can be quickly inserted and deleted at any node
Operation. Because each node in the list holds its place in the list, inserting or deleting an element is only
Up to three elements are affected, unlike vectors that have a storage address for all elements after the operation point
The effect of this is vector incomparable.
The characteristics of the list:
(1) Does not use the continuous memory space to be able to carry on the dynamic operation freely;
(2) can be inserted or deleted at any point in the interior, of course, can also be pushed and pop at both ends.
(3) cannot carry on the internal random access, namely does not support [] the operator and vector.at ();
Lists stores elements sequentially in a linked list, which, compared to vectors (vectors), allows for fast insertion
and deleted, but random access is slower.
1.assign () Assign value to list
Grammar:
void assign (Input_iterator start, Input_iterator end);
The list is assigned the range indicated by the iterator start and end
void assign (Size_type num, const type &VAL);
Assigns num an element that is a value of Val.
2.back () returns a reference to the last element
3.begin () returns the iterator that points to the first element
4.clear () Delete all elements
5.empty () returns True if the list is empty
6.end () returns the iterator at the end
7.erase () Delete an element
Grammar:
Iterator Erase (Iterator loc)//delete element at Loc
Iterator Erase (iterator start, iterator end); Delete the element between start and end
8.front () returns a reference to the first element
9.get_allocator () returns the Configurator of the list
10.insert () insert an element into the list
Grammar:
Iterator Insert (iterator loc, const TYPE &val);
Inserts an element with a value of Val before loc the specified position, returning the iterator that points to the element.
void Insert (Iterator loc, size_type num, const type &VAL);
Inserts the NUM value of Val before the fixed position loc
void Insert (Iterator loc, input_iterator start, Input_iterator end);
Inserts all elements of the interval [start, end] before Loc at the specified position
11.max_size () returns the maximum number of elements the list can hold
12.merge () Merge two list
Grammar:
void merge (list &lst)//link yourself to the LST list
void merge (List &lst, Comp compfunction);
Specifies compfunction, the specified function is used as the basis for comparison.
13.pop_back () deletes the last element
14.pop_front () deletes the first element
15.push_back () Add an element at the end of the list
16.push_front () Add an element to the head of the list
17.rbegin () returns a reverse iterator that points to the first element
18.remove () delete element from list
Grammar:
void Remove (const TYPE &val);
Delete all elements in a linked list that have a value of Val
19.remove_if () deletes elements by specified criteria
20.rend () a reverse iterator pointing at the end of the list
21.resize () Change the size of the list
Grammar:
void resize (size_type num, type val);
Change the size of the list to Num. The extra elements that are added are assigned to VAL22.
22.reverse () reverse the elements of the list
23.size () returns the number of elements in the list
24.sort () to sort list
Grammar:
The void sort ()//is sorted by the list, and the default is ascending
void sort (Comp compfunction), or the specified function compfunction to determine the size of two elements.
25.splice () Merge two list
Grammar:
void Splice (iterator pos, List &lst)//Connect LST to POS location
void Splice (iterator pos, List &lst, iterator del);//Insert the element of Del in the LST to the POS on the current list
void Splice (iterator pos, List &lst, iterator start, iterator end);//Specify range with start and end.
26.swap () Swap two list
Grammar:
void swap (list &lst)//swap LST and elements in the current list
27.unique () Delete duplicate elements in list
Grammar:
void unique ()//delete all duplicate elements in a linked list
void unique (binpred PR);//Specify PR, then use PR to determine whether to delete.
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.