用一维数组 a[7] 顺序存储一个循环队列,队首和队尾指针分别用 front 和 rear 表示, 当前队列中已有 5 个元素:22,30,16,36,58,其中 22 是队首, front 值为 5。队 列初始化时,front 和 rear 的初始值都为-1。请画出对应的存储状态图,当连续做两次出 队运算后,再做两次入队运算,让元素 80,55 依次进队,请再画出对应的存储状态图。
时间: 2023-09-20 09:11:51 浏览: 286
初始状态:
```
+---+---+---+---+---+---+---+
a | | | | | | | |
+---+---+---+---+---+---+---+
0 1 2 3 4 5 6
^ ^
front rear
```
加入 22,30,16,36,58:
```
+---+---+---+---+---+---+---+
a |22 |30 |16 |36 |58 | | |
+---+---+---+---+---+---+---+
0 1 2 3 4 5 6
^ ^
front rear
```
出队两次:
```
+---+---+---+---+---+---+---+
a | | | |36 |58 | | |
+---+---+---+---+---+---+---+
0 1 2 3 4 5 6
^ ^
rear front
```
入队 80,55:
```
+---+---+---+---+---+---+---+
a | | | |36 |58 |80 |55 |
+---+---+---+---+---+---+---+
0 1 2 3 4 5 6
^ ^
rear front
```
存储状态图:
```
+---+---+---+---+---+---+---+
a | | | |36 |58 |80 |55 |
+---+---+---+---+---+---+---+
0 1 2 3 4 5 6
^ ^
rear front
```
阅读全文