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

来源:互联网 发布:mac os 升级老版本 编辑:程序博客网 时间:2024/05/22 14:16
std::deque(双端队列):
定义:
template<

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

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

Member functions

 
(constructor)
constructs the deque 
(public member function) 
(destructor)
destructs the deque 
(public member function) 
operator=
assigns values to the container 
(public member function) 
assign
assigns values to the container 
(public member function) 
get_allocator
returns the associated allocator 
(public member function)
Element access
 
at
access specified element with bounds checking 
(public member function) 
operator[]
access specified element 
(public member function) 
front
access the first element 
(public member function) 
back
access the last element 
(public member function)
Iterators
 
begincbegin
returns an iterator to the beginning 
(public member function) 
endcend
returns an iterator to the end 
(public member function) 
rbegincrbegin
returns a reverse iterator to the beginning 
(public member function) 
rendcrend
returns a reverse iterator to the end 
(public member function)
Capacity
 
empty
checks whether the container is empty 
(public member function) 
size
returns the number of elements 
(public member function) 
max_size
returns the maximum possible number of elements 
(public member function) 
shrink_to_fit
(C++11)
reduces memory usage by freeing unused memory 
(public member function)
Modifiers
 
clear
clears the contents 
(public member function) 
insert
inserts elements 
(public member function) 
emplace
(C++11)
constructs element in-place 
(public member function) 
erase
erases elements 
(public member function) 
push_back
adds elements to the end 
(public member function) 
emplace_back
(C++11)
constructs elements in-place at the end 
(public member function) 
pop_back
removes the last element 
(public member function) 
push_front
inserts elements to the beginning 
(public member function) 
emplace_front
(C++11)
constructs elements in-place at the beginning 
(public member function) 
pop_front
removes the first element 
(public member function) 
resize
changes the number of elements stored 
(public member function) 
swap
swaps the contents 
(public member function)


std::queue(队列):

定义:
template<

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

> class queue;
实现接口:
http://en.cppreference.com/w/cpp/container/queue

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

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

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

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

Member functions

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



std::stack(栈):

定义:
template<

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

> class stack;

实现接口:
http://en.cppreference.com/w/cpp/container/stack

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

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

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

Member functions

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


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