Vector list deque

Source: Internet
Author: User

Vector:
Vector containers use a linear storage structure to access elements randomly (subscript) Like arrays, and insert elements at the end (using the push_back () function ). Features: fast access to elements, but slow insert and delete operations;

List:
A two-way linked list container uses a linked list pointer string to connect to a linear table in a logic sense, but data in physical memory can be discontinuous. Features: The insert, delete, and search operations on elements at any position in the linked list are extremely fast, but they are concatenated by pointers (the pointers here also occupy the memory space ), elements cannot be accessed by subscript, so the access speed of elements in the list container is slower than that in the vector;

Deque:
The dual-end queue container uses a linear table storage structure like a vector, but the only difference with the vector is that deque uses a linear storage structure to store data, each of which is generally 512 bytes in size, called a deque block, all deque blocks are managed using a map block. Each map data item records the first address of each deque block. Therefore, it is not easy to implement the capacity and reverse functions similar to the vector, and the deque container does not need such functions to get and adjust the container size. Features: you can insert and delete elements in the header and tail of the deque block without moving other elements. Therefore, the insert and delete operations are faster than those of the vector. In general, deque is more advantageous than vector when considering the memory allocation policies and operation performance of container elements.

Summary:

Generally,
When many elements are accessed, the efficiency of insertion and deletion is not concerned. It is better to use vector;
When many elements are inserted, deleted, and traversed, it is better to use the list instead of accessing them immediately;
Deque is recommended when a large number of visits are made to the header and tail of a linear table;

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.