Containers for the C + + standard library

Source: Internet
Author: User
Array

The built-in array is packaged, and an array is formed after bundling common operations. The advantage of array is that it is almost identical to the built-in array in time-space efficiency, but it is easier to use than built-in arrays. The size function replaces sizeof (ARR)/sizeof (arr[0]), and the back function replaces the arr[sizeof (arr)/sizeof (Arr[0]-1],array can also swap and compare. The disadvantage of array is the fixed size.

Vector

Container sizes can be dynamically increased and cannot be reduced dynamically. Vectors support subscript access, which is second only to the built-in arrays and array. Vector in the tail of the increase, delete operation is very efficient, other locations are very inefficient. In essence, the vector is a contiguous memory, and when the memory size is not enough, the vector will request a larger chunk of memory to replace the old memory. The advantages and disadvantages of vectors are related to their nature.

Deque

Container size can be dynamically increased and reduced. Deque supports subscript access, but the slowest access. Deque in the head, tail of the increase, removal operation is very efficient, other locations are low. The advantage and disadvantage of deque is that it is essentially multiple contiguous memory, not a block.

List

List is essentially a doubly linked list, so subscript access is not supported. List in any position insertion, deletion is a constant time, in addition to the beginning and tail, more efficient than vector, deque.

Forward_list

Forward_list is essentially a one-way linked list, designed to save space (even the size function is saved). Forward_list does not support subscript access, the operation is also different from other containers, vector, List of INSERT, erase operation is to delete iterator refers to the element, and Forward_ The list is the element that is removed after the element that iterator refers to.

Set

Associative containers, set corresponding to the concept of a set, the advantage is that it can be quickly found.

Map

Associative containers, map corresponding to the concept of a dictionary table, the advantage is that it can be quickly found.

Containers for the C + + standard library

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.