C++标准库__std::deque(双端队列),std::queue(队列),std::stack(栈)__由stl的定义我们就可以看出 queue和stack都是基于deque实现的和常用接口

时间:2022-02-11 17:38:37
std::deque(双端队列):
定义:
template <

    class T,
    class Allocator = std::allocator<T>

>   class  deque ;
实现接口:
接口:
max_size               可以容纳的最大元素个数,为resize提供帮助,是根据成员类型和可以访问的虚拟内存的大小计算出来的。

Member functions

 
constructs the deque 
(public member function)
 
destructs the deque 
(public member function)
 
assigns values to the container 
(public member function)
 
assigns values to the container 
(public member function)
 
returns the associated allocator 
(public member function)
Element access
 
at
access specified element with bounds checking 
(public member function)
 
access specified element 
(public member function)
 
access the first element 
(public member function)
 
access the last element 
(public member function)
Iterators
 
returns an iterator to the beginning 
(public member function)
 
returns an iterator to the end 
(public member function)
 
returns a reverse iterator to the beginning 
(public member function)
 
returns a reverse iterator to the end 
(public member function)
Capacity
 
checks whether the container is empty 
(public member function)
 
returns the number of elements 
(public member function)
 
returns the maximum possible number of elements 
(public member function)
 
(C++11)
reduces memory usage by freeing unused memory 
(public member function)
Modifiers
 
clears the contents 
(public member function)
 
inserts elements 
(public member function)
 
(C++11)
constructs element in-place 
(public member function)
 
erases elements 
(public member function)
 
adds elements to the end 
(public member function)
 
(C++11)
constructs elements in-place at the end 
(public member function)
 
removes the last element 
(public member function)
 
inserts elements to the beginning 
(public member function)
 
(C++11)
constructs elements in-place at the beginning 
(public member function)
 
removes the first element 
(public member function)
 
changes the number of elements stored 
(public member function)
 
swaps the contents 
(public member function)


std::queue(队列):

定义:
template<

    class T,
    class Container = std::deque<T>

>   class  queue ;
实现接口:

queue的三个主要操作接口:
push  <-->   调用deque的push_back来实现;

pop   <-->   调用deque的pop_front来实现;

front <-->   调用deque的front来实现;

back  <-->   调用deque的back来实现;

Member functions

 
constructs the queue 
(public member function)
 
destructs the queue 
(public member function)
 
assigns values to the container adaptor 
(public member function)
Element access
 
access the first element 
(public member function)
 
access the last element 
(public member function)
Capacity
 
checks whether the underlying container is empty 
(public member function)
 
returns the number of elements 
(public member function)
Modifiers
 
inserts element at the end 
(public member function)
 
(C++11)
constructs element in-place at the end 
(public member function)
 
pop
removes the first element 
(public member function)
 
swaps the contents 
(public member function)



std::stack(栈):

定义:
template<

    class T,
    class Container = std::deque<T>

>   class  stack ;

实现接口:

栈的三个主要操作接口:
push <-->   调用deque的push_back来实现;

pop  <-->   调用deque的pop_back实现;

top  <-->   调用deque的back实现;

Member functions

 
constructs the queue 
(public member function)
 
destructs the queue 
(public member function)
 
assigns values to the container adaptor 
(public member function)
Element access
 
access the first element 
(public member function)
 
access the last element 
(public member function)
Capacity
 
checks whether the underlying container is empty 
(public member function)
 
returns the number of elements 
(public member function)
Modifiers
 
inserts element at the end 
(public member function)
 
(C++11)
constructs element in-place at the end 
(public member function)
 
pop
removes the first element 
(public member function)
 
swaps the contents 
(public member function)


由定义我们就可以看出 queue和stack都是基于deque实现的!