Similarities and differences of vector list deque

Source: Internet
Author: User

One of the secrets of Vector's excellent efficiency is the allocation of more memory than the element it accommodates.

Deque compared to vectors, the functional differences are as follows:

· Both ends are able to quickly insert elements and remove elements (vectors only at the tail end).

· Accessing the element is a bit slower than the vector, and there is a more indirect process.

· Deque does not support control over the timing of capacity and memory reallocation.

· The internal structure is a plurality of blocks, inserted before and after, is inserted in the beginning and ends of the block, full of part, and add one more block, so do not need to be like a vector, redistribution, replication.

Deque,vector and List comparison:

· Random access is good, but removing the insertion element in the middle is worse than list.

· Before and after inserting deque and list, the vector is inserted uniformly in the middle, and the insertion is the same for everyone.

Vector is a dynamic array;

Deque similar to a variable array of numbers;

List doubly linked list;

Summarize:

1. If you want to insert or remove frequently in the middle, you use the list.

2. If you are sure that you only need to insert at the tail, random access can be, you use the vector, but, with this, pay attention to his dynamic expansion, the best, to give him roughly the capacity to use;

3. If you need to insert at the tail, random access, then use Deque.

Similarities and differences of vector list deque

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.