List (doubly linked list)
You can scale dynamically without specifying a pre-allocated memory size, because it is stored in a discontinuous memory space and is linked by a pointer.
Because it is a linked list, the performance of random access is not good, but the performance of inserting and deleting at any location is better than vector (the characteristics of the list)
Characteristics:
- Storage address is not continuous, dynamic expansion performance is good
- Insert Delete in any location good performance
- Random Access not supported
Bold as a vector.
Assign ()
Back ()
Clear ()
empty ()
End ()
Erase ()
Front ()
Get_allocator ()
Insert ()
max_size ()
Merge () merges two lists
//自己和lst合并并排序merge(list &lst);//按照某种规则排序merge(list &lst, Comp compfunction );
Pop_back ()
Pop_front () Delete the first element
push_back ()
Push_front () Adds an element to the head of the list
Rbegin ()
Remove () removes an element from the list
//删除链表中所有值为val的元素void remove( const TYPE &val );
remove_if () Delete elements by specified criteria
rend ()
Resize () Change the size of the list
//把list的大小改变到num。被加入的多余的元素都被赋值为valvoid resize( size_type num, TYPE val );
reverse ()
size ()
Sort () Sorts the list
void sort();//为链表排序,默认是升序void sort( Comp compfunction );//采用指定函数compfunction来判定两个元素的大小。
Splice () Merge two lists
void splice( iterator pos, list &lst );//把lst连接到pos的位置void splice( iterator pos, list &lst, iterator del );//插入lst中del所指元素到现链表的pos上void splice( iterator pos, list &lst, iterator start, iterator end );//用start和end指定范围。
swap ()
Unique () Delete duplicate elements in list
Deque (bidirectional queue)
A basic sequence container that adds and removes elements at both ends of a sequence.
Store data in multiple contiguous memory spaces.
Combines the features of list and vector in a balance between the two.
Characteristics:
- Random access is supported, but performance is not as good as vector
- Delete can be inserted anywhere inside, but performance is not list good
- Both ends Push,pop
- Uses more memory than a vector. ( the relationship of pointers?) The list should be like this? )
Constructors creating a new bidirectional queue
deque();//创建一个空双向队列deque( size_type size );// 创建一个大小为size的双向队列deque( size_type num, const TYPE &val ); //放置num个val的拷贝到队列中deque( const deque &from );// 从from创建一个内容一样的双向队列deque( input_iterator start, input_iterator end );// start 和 end - 创建一个队列,保存从start到end的元素。
Operators comparison and assignment bidirectional queues
You can use the [] operator to access a single element in a two-way queue
Assign () sets the value of the bidirectional queue
//start和end指示的范围为双向队列赋值void assign( input_iterator start, input_iterator end); void assign( Size num, const TYPE &val );//设置成num个val。
At () returns the specified element
reference at( size_type pos ); 返回一个引用,指向双向队列中位置pos上的元素
Back () returns the last element
reference back();//返回一个引用,指向双向队列中最后一个元素
Begin () returns the iterator that points to the first element
iterator begin();//返回一个迭代器,指向双向队列的第一个元素
Clear () Delete all elements
Empty () returns True if the two-way queue is null
End () returns an iterator pointing to the tail
Erase () Delete an element
iterator erase( iterator pos ); //删除pos位置上的元素iterator erase( iterator start, iterator end ); //删除start和end之间的所有元素//返回指向被删除元素的后一个元素
Front () returns a reference to the first element
Get_allocator () returns the Configurator for the bidirectional queue
Insert () inserts an element into a two-way queue
iterator insert( iterator pos, size_type num, const TYPE &val ); //pos前插入num个val值void insert( iterator pos, input_iterator start, input_iterator end );//插入从start到end范围内的元素到pos前面
Max_size () returns the maximum number of elements that a two-way queue can hold
Pop_back () Delete the trailing element
Pop_front () Delete the element of the head
Push_back () Adds an element to the tail
Push_front () Adds an element to the head
Rbegin () returns a reverse iterator pointing to the tail
Rend () returns a reverse iterator pointing to the head
Resize () Change the size of the two-way queue
Size () returns the number of elements in a two-way queue
Swap () and another bidirectional queue exchange element
void swap( deque &target );// 交换target和现双向队列中元素
Comparison of the three
vector 是一段连续的内存块,而deque 是多个连续的内存块, list 是所有数据元素分开保存,可以是任何两个元素没有连续。vector 的查询性能最好,并且在末端增加数据也很好,除非它重新申请内存段;适合高效地随机存储。list 是一个链表,任何一个元素都可以是不连续的,但它都有两个指向上一元素和下一元素的指针。所以它对插入、删除元素性能是最好的,而查询性能非常差;适合大量地插入和删除操作而不关心随机存取的需求。deque 是介于两者之间,它兼顾了数组和链表的优点,它是分块的链表和多个数组的联合。所以它有list好的查询性能,有vector好的插入、删除性能。如果你需要随即存取又关心两端数据的插入和删除,那么deque是最佳之选。
C + + Standard Template Library _note (2)