C ++ standard template library container classification

Source: Internet
Author: User

In the c ++ standard template library, there are three types of containers: sequential containers, associated containers, and container adapters. An ordered container is a linear ordered cluster. The underlying implementation relies on linked lists or arrays. An associated container is a non-linear tree structure that stores data in key-value format. These two types are described in the previous two articles, and the third type of container is the container adapter. As the name suggests, an adapter is a mechanism that allows an object to behave in line with the behavior of another object. Container adapter is an interface that enables an existing container type to work in a different abstract type. C ++ STL contains three adapters: stack, queue, and priority priority_queue. The three adapters provided in www.2cto.com STL can be implemented by an ordered container. By default, stack and queue are implemented based on the deque container, while priority_queue is implemented based on the vector container. Of course, when creating an adapter, you can also specify a specific implementation container. When creating an adapter, you can specify a specific sequence container on the second parameter to override the default Implementation of the adapter. Due to the characteristics of the adapter, an adapter cannot be implemented by any sequential container. Stack is characterized by post-import, first-out, so the basic container associated with it can be any sort of ordered container, because these container type structures can provide stack operation requirements, they all provide push_back, pop_back, and back operations. The queue features first-in-first-out, and the adapter requires that the associated basic container must provide the pop_front operation, so it cannot be built on the vector container; the priority_queue adapter of the priority queue requires random access, so it cannot be created on the list container.

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.