我研究数据结构,我想问一下STL容器相当于什么。
例如
关于C++标准库容器,标准本身尽量不过多提及实现。然而,对插入、删除、查找、范围插入等复杂性的非常具体的限制意味着大多数实现对容器使用相同类型的数据结构。关于你的一些例子:
我相信STL遵循这些实现。
我认为将 std::map<> 限定为“对”是不正确的。实际上,有一个名为 std::pair<> 的utility,它实际上只是一对。 std::map<> 存储唯一键和非唯一值的方式使得可以使用类似于数组的语法,其索引可以是数字类型,也可以不是数字类型。
编辑:将“容器”更正为“实用程序”,感谢 juanchopanza。
集合和多重集合-二叉搜索树
map 和 multimap - 二叉搜索树
双端队列 - 双端队列
hash*
容器是作为哈希表实现的哈希关联容器。
例如。 hash_map
包含使用哈希表查找的 pair<key,value>
。
在位集中
the individual elements are accessed as special references which mimic bool elements
vector = dynamic array
queue = queue
stack = stack
priority_queue = priority queue based on binary heap
priority_queue can be implemented using
1. sorted array
2. sorted list ( unrolled list, skip list etc)
3. any other heap like Fibonacci heap, binomial heap
list = doubly linked list
set = set based on AVL Tree ( usually )
can implemented using any other binary balancing tree like
1. Binary Search Tree
2. Red black Tree
3. Splay Tree
slist = single linked list
map = map based on Red Black Tree ( usually )
where every node is 'pair' structure
can implemented using any other binary balancing tree like
1. Binary Search Tree
2. AVL Tree
3. Splay Tree
deque = deque
hash_set = set implemented using hash
hash_map = hash table
hash = 'Not Available', used as functor
C++ 标准并未对容器强加特定的数据结构,而是定义了一组要求。这意味着实现必须仅满足上述要求,这些要求主要涉及不同操作的时间复杂度、引用稳定性和迭代器失效,才能被视为符合标准。
但是,某些要求和性能期望的结合迫使大多数库(libc++、libstdc++、MSVC)为每个容器使用特定的数据结构。
std::array
:固定大小数组std::vector
:动态大小数组std::deque
:哈希数组树std::forward_list
:单链表std::list
:双向链表std::set
/std::map
:自平衡BST(红黑树)std::unordered_set
/std::unordered_map
:哈希表(分离链哈希表)