The road to learning C++ primer-(Chapter 16 List of STL Templates)

The llist template class is declared in the list header file, which represents the doubly linked list class. Except for the first and last one, every element in the middle is linked to the two elements before and after. The list cannot be array representation and supports random access.

The list emphasizes the fast insertion and deletion of elements, the availability is the best and the sequence is the fastest, but the sorting is slower.

Such as:

int arr[5] = {1,2,,3,4,5};
list<int>a(arr,arr + 5);
a[0];    //这样是不可以的 本身特性就是没有这些

List has several commonly used member functions:

 Among them, the main difference between solice and insert (insert element) is: insert inserts a copy of the original interval to the target address, while splice directly transfers the original interval to the target interval. After the splice method is executed, the iterator is still valid, and the iterator is added What is set is to point to the element of the original list. After relocating it to the target element after splice, this iterator still points to the same element

 unique: only compress adjacent identical values ​​into a single value. If the same value is not adjacent, it cannot be compressed into a single value, so you can use the sort function in the member and then use unique, which means that the first sorting will be the same Be next to each other, and then use unique to compress.

 

Guess you like

Origin blog.csdn.net/z1455841095/article/details/82734618
Recommended