STL概述

STL = Standard Template Library,标准模板库。包含容器(Container)、迭代器(Iterator)、算法(algorithm)。

一、容器

Sequence containers(序列容器)

Sequence containers implement data structures which can be accessed sequentially.

 
(since C++11)
static contiguous array
(class template)
 
dynamic contiguous array
(class template)
 
double-ended queue
(class template)
 
(since C++11)
singly-linked list
(class template)
 
doubly-linked list
(class template)

 Associative containers(关联容器)

Associative containers implement sorted data structures that can be quickly searched (O(log n) complexity).

 
set
collection of unique keys, sorted by keys
(class template)
 
map
collection of key-value pairs, sorted by keys, keys are unique
(class template)
 
collection of keys, sorted by keys
(class template)
 
collection of key-value pairs, sorted by keys
(class template)

Unordered associative containers(未排序关联容器)

Associative containers implement unsorted (hashed) data structures that can be quickly searched (O(1) amortized,O(n) worst-case complexity).

 
(since C++11)
collection of unique keys, hashed by keys
(class template)
 
(since C++11)
collection of key-value pairs, hashed by keys, keys are unique
(class template)
 
(since C++11)
collection of keys, hashed by keys
(class template)
 
(since C++11)
collection of key-value pairs, hashed by keys
(class template)

Container adaptors(容器适配器)

Container adaptors provide a different interface for sequential containers.

 
adapts a container to provide stack (LIFO data structure)
(class template)
 
adapts a container to provide queue (FIFO data structure)
(class template)
 
adapts a container to provide priority queue
(class template)

Member map

This is a comparison chart with the different member functions present on each of the different containers:

 Sequence containersAssociative containers 
Headers<vector><deque><list><set><map><bitset>
Memberscomplexvectordequelistsetmultisetmapmultimapbitset
 constructor*constructorconstructorconstructorconstructorconstructorconstructorconstructorconstructor
destructorO(n)destructordestructordestructordestructordestructordestructordestructor 
operator=O(n)operator= operator= operator= operator= operator= operator= operator= operators
iteratorsbeginO(1)beginbeginbeginbeginbeginbeginbegin 
endO(1)endendendendendendend 
rbeginO(1)rbeginrbeginrbeginrbeginrbeginrbeginrbegin 
rendO(1)rendrendrendrendrendrendrend 
capacitysize*sizesizesizesizesizesizesizesize
max_size*max_sizemax_sizemax_sizemax_sizemax_sizemax_sizemax_size 
emptyO(1)emptyemptyemptyemptyemptyemptyempty 
resizeO(n)resizeresizeresize     
element accessfrontO(1)frontfrontfront     
backO(1)backbackback     
operator[]*operator[] operator[]    operator[]  operator[]
atO(1)atat      
modifiersassignO(n)assignassignassign     
insert*insertinsertinsertinsertinsertinsertinsert 
erase*eraseeraseeraseeraseeraseeraseerase 
swapO(1)swapswapswapswapswapswapswap 
clearO(n)clearclearclearclearclearclearclear 
push_frontO(1) push_frontpush_front     
pop_frontO(1) pop_frontpop_front     
push_backO(1)push_backpush_backpush_back     
pop_backO(1)pop_backpop_backpop_back     
observerskey_compO(1)   key_compkey_compkey_compkey_comp 
value_compO(1)   value_compvalue_compvalue_compvalue_comp 
operationsfindO(log n)   findfindfindfind 
countO(log n)   countcountcountcountcount
lower_boundO(log n)   lower_boundlower_boundlower_boundlower_bound 
upper_boundO(log n)   upper_boundupper_boundupper_boundupper_bound 
equal_rangeO(log n)   equal_rangeequal_rangeequal_rangeequal_range 
unique members capacity
reserve
 splice
remove
remove_if
unique
merge
sort
reverse
    set
reset
flip
to_ulong
to_string
test
any
none

Amortized complexity shown. Legend: O(1) constant < O(log n) logarithmic < O(n) linear; *=depends on container

Container adaptors:

 Container Adaptors
Headers<stack><queue>
Membersstackqueuepriority_queue
 constructor*constructorconstructorconstructor
capacitysizeO(1)sizesizesize
emptyO(1)emptyemptyempty
element accessfrontO(1) front 
backO(1) back 
topO(1)top top
modifierspushO(1)pushpushpush
popO(1)poppoppop

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值