知识卡片
环形队列预留空槽
队列按先进先出删除等待最久的元素。
容量 n 的环形数组让 head 指向队首、tail 指向下次写入处,二者回绕;head=tail 表示空,因此预留一个槽位,以 tail 的下一位置等于 head 表示满,最多存 n−1 项。
入队与出队均为 O(1)。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
- · 环形队列预留空槽
原书出处 · 1 处
- 第10章 基本数据结构 · 查看原书依据
sense that location 1 immediately follows location n in a circular order. When Q.head = Q.tail, the queue is empty. Initially, we have Q.head = Q.tail = 1. An attempt to dequeue an element from an empty queue causes the queue to underflow. When
参考来源
- 位置:《算法导论(第4版)》第 10 章 10.1.3 节(`OEBPS/chapter010.xhtml`,文本字符 [7500, 10300);图 10.3/Art_P369)。
- 结论依据:原文定义 FIFO、head/tail 语义、空满判定及 n−1 元素容量。
- 原始内容:sense that location 1 immediately follows location n in a circular order. When Q.head = Q.tail , the queue is empty. Initially, we have Q.head = Q.tail = 1. An attempt to dequeue an element from an empty queue causes the queue to underflow. When