Summary of C + + technical Issues-7th: map, vector, list, deque each use occasion

Source: Internet
Author: User

Maps are associative, andvectors,lists,anddeque are sequential in type.

Map: Underlying mechanism rb-tree(red-black tree), automatic ordering of elements, key-value pairs.


Vector: operates in a similar way to array, with dynamic space growth. is a continuous space that supports random access.

Advantages:

? Memory is dynamically growing and does not require a specified memory size.

? Support for random access, i.e. support [] and vector.at ().

Disadvantages:

? Internal Insert delete operation is inefficient.

? push and popare only available at the end of the vector .


List: The use of space is absolutely accurate, not a waste of it. Deleting inserts is simple, but does not support random access. Bidirectional linear list.

Advantages:

? Easy to insert and remove.

? Can be push,popon both ends.

Cons: cannot be accessed randomly.


Deque: Continuity space for bidirectional openings. The insertion and deletion of elements are made at each end of the tail.

Advantages:

? Random access.

? Easy to insert and remove.

? Can be push,popon both ends.

Cons: Internal implementation is complex and less efficient. Sort, etc. not applicable.


Summary of Use occasions:

? Requires efficient access, not in terms of insertion and deletion efficiency, using vectors.

? It takes a lot of insertions and deletions, doesn't care about access, uses list.

? Care access, and both ends of the data are inserted and deleted, using deque.

? Key-value pairs, one-to-one mapping, using map.

Summary of C + + technical Issues-7th: map, vector, list, deque each use occasion

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.