22 Container Adapter for Standard Template Library STL

overview

        When it comes to adapters, our first impression is to think of the adapter pattern in the design pattern: convert the interface of one class into the interface of another class, so that two classes that are originally incompatible and cannot cooperate can work together. The container adapter in STL is similar to this, it is a class template that encapsulates the sequence container, and it provides some different functions and interfaces on the basis of the general sequence container. It is called a container adapter because it provides different functions and interfaces by adapting the existing interfaces of existing containers.

        The container adapters in STL include: stack, queue and priority_queue, which are introduced below.

stack

        1. stack is an adapter class template that encapsulates the deque container. The default implementation is a last-in-first-out push stack, which pushes and pops elements from the tail of the container (the top of the stack).

        2. Before using stack, you need to include its header file.

#include <stack>
using namespace std;

        The main interfaces provided by the stack container adapter can be found in the table below.

interface

Remark

size()

Returns the number of elements in the stack

empty()

Guess you like

Origin blog.csdn.net/hope_wisdom/article/details/130669931