Comparison between vector and deque in STL

Source: Internet
Author: User

Similarities:

1. Ordered container

2. Dynamic one-dimensional array

3. the time complexity of insert and delete operations in the middle is O (n );

4. Quick and Random Access to elements

 

Differences:

1. Vector supports push_back and pop_back operations. deque supports push_back, push_front, pop_back, and pop_front operations;

2. push_back of vector, the time complexity of pop_back operations is O (1), and the time complexity of header insertion and deletion operations is O (n); push_back, push_front, pop_back, the time complexity of pop_front operations is O (1 );

3. vector is a continuous bucket; deque is a page or block;

4. Reserved space for vector; no reserved storage space for deque.

Related Article

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.