STL中容器的底层实现

vector

vector底层就是一块内存(可以说是一个数组),由3个指针管理

详细参见https://blog.csdn.net/weixin_40673608/article/details/87103742

list
list底层是一个双向链表

详细参见https://blog.csdn.net/weixin_40673608/article/details/87865027

deque
deque底层是一个指针数组,数组中的指针指向另外一个数组

stack
stack底层就是deque,只不过禁掉了一些接口,使得它的操作看起来像stack

queue
queue底层就是deque,只不过禁掉了一些接口,使得它的操作看起来像queue

heap(幕后)
heap提供的是算法,分为max-heap和min-heap

priority_queue
priority_queue底层是vector,处理规则使用的是heap的处理规则

set、multiset、map、multimap
底层是红黑树,set不同于map的就是它的映射是它本身

unordered_set、unordered_map
底层是哈希表
 

参考:STL中容器底层数据结构总结

猜你喜欢

转载自blog.csdn.net/juluwangriyue/article/details/115189476
今日推荐