容器适配器

编程语言 / C++ 标准库

本地源文件:docs/lang__csl__container-adapter.md

容器适配器

STL (std::stack) 是一种后进先出 (Last In, First Out) 的容器适配器,仅支持查询或删除最后一个加入的元素(栈顶元素),不支持随机访问,且为了保证数据的严格有序性,不支持迭代器.

头文件

---|---

### 定义

---|---

成员函数

以下所有函数均为常数复杂度

  • top() 访问栈顶元素(如果栈为空,此处会出错)
  • push(x) 向栈中插入元素 x
  • pop() 删除栈顶元素
  • size() 查询容器中的元素数量
  • empty() 询问容器是否为空

简单示例

---|---

## 队列

STL [队列](../../../ds/queue/)(`std::queue`) 是一种先进先出 (First In, First Out) 的容器适配器,仅支持查询或删除第一个加入的元素(队首元素),不支持随机访问,且为了保证数据的严格有序性,不支持迭代器.

### 头文件

---|---

定义

---|---

### 成员函数

**以下所有函数均为常数复杂度**

  * `front()` 访问队首元素(如果队列为空,此处会出错)
  * `push(x)` 向队列中插入元素 x
  * `pop()` 删除队首元素
  * `size()` 查询容器中的元素数量
  * `empty()` 询问容器是否为空

### 简单示例

---|---

优先队列

优先队列 std::priority_queue 是一种 ,一般为 二叉堆

头文件

---|---

### 定义

---|---

成员函数

以下所有函数均为常数复杂度

  • top() 访问堆顶元素(此时优先队列不能为空)
  • empty() 询问容器是否为空
  • size() 查询容器中的元素数量

以下所有函数均为对数复杂度

  • push(x) 插入元素,并对底层容器排序
  • pop() 删除堆顶元素(此时优先队列不能为空)

简单示例

---|---

* * *

> __本页面最近更新: 2026/1/7 08:56:54,[更新历史](https://github.com/OI-wiki/OI-wiki/commits/master/docs/lang/csl/container-adapter.md)
>  __发现错误?想一起完善?[在 GitHub 上编辑此页!](https://oi-wiki.org/edit-landing/?ref=/lang/csl/container-adapter.md "edit.link.title")
>  __本页面贡献者:[ouuan](https://github.com/ouuan), [Ir1d](https://github.com/Ir1d), [Early0v0](https://github.com/Early0v0), [Tiphereth-A](https://github.com/Tiphereth-A), [ksyx](https://github.com/ksyx), [akakw1](https://github.com/akakw1), [aofall](https://github.com/aofall), [Enter-tainer](https://github.com/Enter-tainer), [Haohu Shen](mailto:haohu.shen@ucalgary.ca), [Lewy Zeng](mailto:zengxingchen@csu.edu.cn), [Suyun514](mailto:suyun514@qq.com), [william-song-shy](https://github.com/william-song-shy), [Xeonacid](https://github.com/Xeonacid)
>  __本页面的全部内容在**[CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/deed.zh) 和 [SATA](https://github.com/zTrix/sata-license)** 协议之条款下提供,附加条款亦可能应用