C + + STL sequence container advantages and disadvantages records

Source: Internet
Author: User

There are three types of sequential container vector,list,deque in STL. Performance description for each of them

Vector

The inside of the vector is managed by a continuous dynamic array of memory, each push_back an element and placed at the end of the array.

This way, through continuous memory space management, we can easily go through the subscript index to the value, at the end of the insertion and deletion of the efficiency is very high.

When inserting and deleting inside the vector, it causes the vector container element to move to the position, so the performance is poor

Deque

Deque is a double-ended queue that inserts and deletes elements at the end of the line. When deleted at the end of the high efficiency, in the middle position will lead to moving position, inefficient

List

Double-ended linked list, insert and delete just move the internal pointer position, so very fast, find the words need to go through the previous element in turn, poor performance

C + + STL sequence container advantages and disadvantages records

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.